Skip to content

Global

Prior to “scoped” SQLite databases for each val, which landed in 2026, every Val Town user account has had its own global SQLite database (since 2023). In most cases, val-scoped databases make more sense, but account-scoped (global) databases will continue to work forever.

We typically refer to your user account database as either “account-scoped” or “global.”

Either import statement below will import the account-scoped sqlite object.

Global SQLiteRun in Val Town ↗
import { sqlite } from "https://esm.town/v/std/sqlite/global.ts";
import { sqlite } from "https://esm.town/v/std/sqlite"; // also works

Note that the rows array returned from global sqlite is an array of arrays, whereas the rows object returned by scoped sqlite is an array of objects.

QueryingRun in Val Town ↗
import { sqlite as global } from "https://esm.town/v/std/sqlite/global.ts";
import { sqlite as scoped } from "https://esm.town/v/std/sqlite/main.ts";
// Returns an array of arrays
const { rows } = await global.execute("SELECT * FROM users;");
// Returns an array of objects
const { rows } = await scoped.execute("SELECT * FROM users;");

See usage docs for more detail on querying.

There is currently no built-in way to migrate your existing global databases to val-scoped ones (should you want to), but you can do so easily in userspace. Import this migrate-sqlite val (credit and thanks to @nbbaier) to migrate tables/views/indexes/triggers from your Val Town account-based (global) database to a val-scoped database. Also remember to change the imports from global to scoped sqlite for any files that read/write.