5 ms·
Sqlite to Rest
- hprotagonist 7y agoJeff Knupp's sandman2 (https://github.com/jeffknupp/sandman2 https://github.com/jeffknupp/sandman2) has long been my go-to project for when i need to do this. I don't have to very often, but it is _very_ handy when I do! Semi-related (kind of the inverse) tool is simon w's datasette (https://github.com/simonw/datasette https://github.com/simonw/datasette) which gives you a readonly view into a sqlite database, conveniently exposed as a website. I've fired that up in meetings before to general shock and acclaim...
- ahje 7y ago> simon w's datasette That's awesome. Thanks for the tip!
- networked 7y agoThere are many other projects like this, too. I have a list at https://github.com/dbohdan/automatic-api/ https://github.com/dbohdan/automatic-api/. Added: This type of software lacks a standard name and an established "format" (like HTTP servers or word processors have a "format"), so it is hard to discover other projects even when you are aware of a few. I've taken to calling them "automatic API servers" and promoted the term a bit. Some projects have adopted the GitHub topic "automatic-api" (https://github.com/topics/automatic-api https://github.com/topics/automatic-api) as a result. My hope is that a name and a search tag will help with discovery and make it more of a distinct type of product.
- mooreds 7y agoThanks for that list. There is so much data locked up in databases that could benefit from being turned into an API. To say nothing of CSVs and PDFs.
- BerislavLopac 7y agoThere is also Presto: https://prestodb.github.io/ https://prestodb.github.io/ If you ever saw AWS Athena, that's what it is based on.
- bdcravens 7y agoPerhaps I'm missing something, but I don't see how Presto fits in with these other projects.
- BerislavLopac 7y agoIt was in response to the comment mentioning Datasette, which takes data from a source and puts it into a database. Presto allows you to access data from various sources using SQL syntax.
- snthpy 7y agoI think you were thinking of dataset (https://dataset.readthedocs.io/en/latest/ https://dataset.readthedocs.io/en/latest/) rather than datasette mentioned in the parent. Still quite different to Presto which looks more like Ibis.
- punnerud 7y agoNote: This is for NodeJS. Is there some good practice/frameworks to go the other way around? Often find my self crawling data to a database.
- punnerud 7y agoPart of it in a different (earlier) HN-post: https://news.ycombinator.com/item?id=20399294 https://news.ycombinator.com/item?id=20399294
- kbumsik 7y agoI'm not familiar with those kind of approach but why not just use SQL? I'm genuinely curious.
- Quarrelsome 7y agosqlite doesn't need the full server, it runs directly off a file on disk so there's minimal setup. However sqlite is supposed to be single-user only so idk.
- TickleSteve 7y agoThe single user in this case is the webserver. The webserver can itself serve multiple users if done in a single-threaded fashion. SQLite can also support multiple threads reading, but is limited to file-locking for write-access IIRC.
- lf-non 7y agoIf someone is interested in a similar solution for GraphQL, GRelDAL [1] (authored by me) is an alternative (though it is slightly lower level and requires mapping of data sources through code). Also given support for multiple databases, it is possible to start out with sqlite and later migrate to a database server (postgres or mysql). [1] https://gql-dal.github.io/greldal/ https://gql-dal.github.io/greldal/
- Quarrelsome 7y agoDoes this have hardcore locking in it? Last I knew sqlite doesn't support multi-users so this would just fall over with more than one client concurrently inserting data unless you throttle them into synchronous access.
- SQLite 7y agoSQLite supports multiple simultaneous connections to the database from separate processes. It just does not let more than one connection write at a time. SQLite takes care of serializing access for you - you don't have to put any synchronization code in your application. Your app just needs to be prepared to retry an insert if it gets back an SQLITE_BUSY result code.
- Quarrelsome 7y agoah, thanks for that. I appreciate knowing more.
- iakh 7y agoIsn't that worse though? Having to add retry logic seems to be more complex than a lock or singleton.
- icebraining 7y agoIt does have a lock, and you can set a busy timeout to wait instead of immediately getting an error from SQLite.
- umvi 7y agoIt seems like you can get SQLITE_BUSY even if you are a reader if someone else happens to be writing... I want to like SQLite but that just seems like a deal breaker
- SQLite 7y agoOnly in ROLLBACK journalling mode. Set "PRAGMA journal_mode=WAL" and this does not happen.
- jatsek 7y agoI guess it’s a good place to mention https://github.com/PostgREST/postgrest https://github.com/PostgREST/postgrest as well
- CameronNemo 7y agoWas looking for this one. Implemented in Haskell too!
- coconut_crab 7y agoIt took me awhile to parse the title because Rest isn't in all caps. Initially I thought sqlite is going to be retired or something... but then again English is not my native language.
- BerislavLopac 7y agoTechnically, REST should be spelled ReST anyway. ;)
- anyzen 7y agoSo I wasn't the only one... I initially read "Rust". :)
- oaiey 7y agoI just read OData yet another way. OData at least pretends to be a standard ;).
- gloflo 7y agoWhat would example HTTP queries look like?
- felixfbecker 7y agoThe search query parameter syntax with support for >=, <=, !=, etc is interesting
- deleted 7y ago[deleted]
- finchisko 7y agoDoes this work for any table without any modification or just the beer table? Also documentation is bit weird. Eg API section starts with some require a then there are two CLI commands (generateSkeleton, getSqliteRouter). Does it mean I can generate skeleton without using CLI?
- everdev 7y agoI always found REST (and GraphQL or any API for that matter) tedious as it's basically abstracting SQL queries. To my knowledge the abstraction is necessary to mitigate SQL injection and data permissions. With RLS in Postgres, I think the data access problem has largely been solved where someone with the wrong JWT simply can't query other people's data if RLS is setup properly. However, I don't know of a way to lock down a PostgresDB enough for clients to be able to write their own SQL statements. It's easy enough to remove operations like DROP TABLE xx; but it seems like for a client to safely query a database we're stuck writing these boilerplate abstractions (or auto-generating them now).
- empath75 7y agoRest also means you don’t care about the database schema.
- ahvetm 7y agoBackend services are about more than serving data, wouldn't you say?
- 7h3kk1d 7y agoMost are, but I have definitely worked on projects that weren't
- dpacmittal 7y agoWith front-end development getting increasingly popular, I think backend is starting to become just a thin wrapper around database. If database can be securely locked down enough, a lot of business logic can be shifted to the front-end.
- dvlsg 7y agoThen you can't use it across apps, though. Say for example you have a web front end, a mobile app, and a service receiving web hooks that all want to execute the same action. If you have that in a client layer, you'll be writing it 3 times. Moving logic to the client comes with pros, too (like being easier to work offline), but it definitely has downsides as well.
- stochastimus 7y agoI’m so glad to see this work and other projects like it. The relational database doesn’t need to be abandoned to put any interface over it you like.
- tga 7y agoHasura (https://hasura.io https://hasura.io) is an awesome similar project for getting a GraphQL API (including live subscriptions) automatically from a PostgreSQL database.
- blacksqr 7y agohttp://htsql.org/ http://htsql.org/ "HTSQL is a comprehensive navigational query language for relational databases."
- lovetocode 7y agoA neat project and some of the other comments have shared similar projects for other databases. How do projects like this address security concerns? Specifically, mass assignment attacks?
- ovi256 7y agoIn the Python world, Django Rest Framework does this (and a lot more!). The out-of-box getting started experience is not as smooth though, as you need to define serializers and views objects too. Of course, they're probably going to be useful for more later.