Articles ·
Put a SQLite file online
You have a SQLite file on your own machine and want to query it from somewhere else. One upload gives it an HTTP API, and one download brings it back.
You have a SQLite file on your own machine. You want to query it from somewhere else: a script on a server, a function, a notebook, an agent. Copying the file to each place gives you several copies that drift apart. Putting it in one place with an HTTP API gives you one.
Upload it
curl -X PUT --data-binary @books.db \ https://api.served.dev/v1/databases/books/upload \ -H "Authorization: Bearer $SERVED_KEY"
That is the whole move. The database books now exists and holds what your file held: the tables, the indexes, the views, the triggers, and any full-text index.
If a program has the file open, or it has a -wal file beside it, take a clean copy first and upload that:
sqlite3 books.db ".backup copy.db"
A file over 100 MB goes in three steps, up to 5 GB.
Query it from anywhere
curl https://api.served.dev/v1/databases/books/query \ -H "Authorization: Bearer $SERVED_KEY" \ -d "SELECT title, year FROM books ORDER BY year DESC LIMIT 5"
The answer is JSON:
{"columns": ["title", "year"],
"rows": [["Piranesi", 2020], ["The Overstory", 2018]],
"rows_affected": 0, "last_insert_id": 0}
Anything that can make an HTTP request can do this. The docs have the same call in Python and JavaScript, each a few lines with nothing to install.
It is a database, so it takes writes too. An INSERT or an UPDATE sent the same way changes it for everyone who reads it next.
A key for this database alone
The key you made first works for every database on your account. For a script that only needs books, make a second key on the dashboard and limit it to books. That key opens this one database and no other.
Bring it back
curl -o books.db https://api.served.dev/v1/databases/books/download \ -H "Authorization: Bearer $SERVED_KEY"
The download is a consistent SQLite snapshot taken when you request it. Open it with sqlite3, or with the SQLite tool you used to create it.
Or keep working on your own copy
If the file is something you build, such as a dataset you put together each night, keep building it where you do now and make the upload the last step of the script that builds it:
./build-books.sh curl -sf -X PUT --data-binary @books.db \ https://api.served.dev/v1/databases/books/upload \ -H "Authorization: Bearer $SERVED_KEY"
An upload replaces the database in one step: readers see the old one until the new one is in place, and the new one after.
The file is checked before it replaces anything. One that SQLite cannot read is refused, and the database stays as it was.
Served is hosted SQLite. Real SQLite behind an HTTP API, $5 a month, and the file is yours to download whenever you like.