{
"$type": "site.standard.document",
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreif73ylahemus6sijueq6sjaul6hpogrvx5wxnxqycoq7nzztjyzu4"
},
"mimeType": "image/png",
"size": 4933
},
"description": "Every user gets a database interface!",
"path": "/scoped-databases",
"publishedAt": "2026-01-23T00:00:00.000Z",
"site": "at://did:plc:a2rdzfdxkjwerrfrpbwcipb2/site.standard.publication/3jd443afc2222",
"textContent": "Every val now gets its own SQLite database, and a powerful database UI. This\nmakes it even easier for your vals to persist data and then more transparent to\nsee what data exists, update it manually if you need to, and run queries against\nthe val-specific database.\n\nThis also unlocks new ways to collaborate: when you fork one of your own\nprojects, you can choose to fork the database too, so that the new forked val\ncontains a copy of the old database.\n\nCode example\n\nUsing the std/sqlite val to access the val\ndatabase:\n\n\n\nDemo\n\n<iframe width=\"100%\" height=\"450\" src=\"https://www.youtube.com/embed/LktJyCxUxU?si=PiBoCkfHPBqXQ5Kl\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen></iframe>\n\nWith the built-in SQLite browser you can:\n\n- Add and rename columns\n- Delete rows\n- Get the schema of any table\n- Run queries\n- Export tables as CSV\n- Dump the database as SQL\n\nHistory\n\nIn 2023 we launched\nSQLite\nfor every Val Town user, powered by our friends at Turso.\nVals could use the database with zero configuration and total control. A lot of\nthe most interesting vals are built on this - my\nBluesky ThinkUp Tribute\nval uses SQLite to store people's social media bios, and\ndevstats uses the\ndatabase to track statistics about our repository.\n\nBut because databases were scoped to users and organizations, they contained\nintermixed data: it's impossible to tell a priori which data came from which\nval. Scoped databases fix that problem, eliminating conflicts between different\nvals and making it easy to just browse val-specific data.\n\nSecurity\n\nWe've designed scoped databases to be more secure, too: accessible only by the val itself, so vals can't reach into scoped data living somewhere else. This makes it a lot safer to work on SQLite databases too, because your\nschema changes can't affect any other vals.\n\nUnder the hood, we've added project-scoped API tokens to make this work: each\nval automatically gets a temporary API token as the \nenvironment variable. That API token has always belonged to a user, but now it\nbelongs to a val as well, which gives it specific val superpowers.\n\nExisting databases will stick around\n\nWe're supporting both val-scoped and user-scoped databases for the long term:\nthere are uses to both, and there's no reason to force everyone into a gnarly\nupgrade path. But val scoped databases are definitely recommended for new\nprojects: they make a lot of things easier, and come with a powerful UI.\n\nThanks Turso for the continued collaboration!\n\nWe've provisioned thousands of databases and this will add even more - but it's\npossible because Turso runs SQLite in the cloud. This feature really relies on\nsome tricks from Turso too, like forking databases by\nseeding from point-in-time backups.",
"title": "Every val gets a database!"
}