4 ms·
I've thought a bit about the problem of exposing your underlying database - that's obviously a problem for creating a stable API, because it means you may be un
by simonw 5y ago
I've thought a bit about the problem of exposing your underlying database - that's obviously a problem for creating a stable API, because it means you may be unable to change your internal database schema without breaking all of your existing API clients!
With Datasette, my solution is to specifically publish the subset of your data in the schema that you think is suitable for exposing to the outside world. You might have an internal PostgreSQL database, then use my db-to-sqlite tool - https://datasette.io/tools/db-to-sqlite https://datasette.io/tools/db-to-sqlite - to extract just a small portion of that into a SQLite database which you periodically publish using Datasette.
The other idea I have is to use views. Imagine having a PostgreSQL database with a couple of documented SQL views that you expose to the outside world. Now you can change your schema any time you like, provided you then update the definition of those views to expose the same shape of data that your external, documented API requires.
As with all APIs of this sort, adding new columns is fine - it's only removing columns or changing the behaviour of existing problems that will cause breakages for clients.
- transfire 5y agoI wonder if database engines will ever have versioning, such that it would always be possible to see the database as it was at different points in time.
- edtechdev 5y agoTerminusDB is a graph database that supports versioning https://terminusdb.com/ https://terminusdb.com/
- simonw 5y agoMariaDB has this and it sounds really powerful: https://simonwillison.net/2018/Apr/25/system-versioned-tables/ https://simonwillison.net/2018/Apr/25/system-versioned-table...