SQLite
Use SQLite as the MainSDK local data driver - offline development with no database server, main.yaml overlays, testing, and why production refuses it.
SQLite is the local driver behind db. It keeps your records in a file on your machine, so mainsdk dev runs offline with no database server, cloud account or connection string. Your code calls the same db.<model>.for(user) methods it calls in production. Pick it for local development and quick prototypes; production uses Postgres, Neon or Supabase, and mainsdk check enforces that.
Interfaces it serves
Pick SQLite in main.yaml for any of these. Your calls stay the same, and you can swap later.
dbBuilding for 0.3Driver sqlite SQLite (local only)
db:
driver: sqliteBefore you start
Nothing to set up. SQLite is an embedded database that runs inside your app's process, so there is no server, account or key.
- Install MainSDK and run
mainsdk dev. Every interface ships a local driver, and SQLite is the one fordb. - Pick a production driver early, such as Postgres, so your production overlay is ready before your first deploy.
Configure
Keep SQLite in your development overlay and a real driver in production.
db:
driver: sqlitedb:
driver: postgres
regions: { us: secret:DB_US, eu: secret:DB_EU, in: secret:DB_IN } # suggested namesWhere the SQLite file lives, and how the local driver handles the us, eu and in regions, are not defined yet. Field labels under db.fields apply as they do on any driver.
Use it
import { auth, db } from "mainsdk";
export async function GET(req: Request) {
const session = await auth.require(req);
const orders = await db.orders.for(session.user).list({ limit: 20 });
return Response.json(orders);
}The same code runs unchanged when production points db at Postgres.
Local development and testing
mainsdk dev: runsdbon SQLite with no provider key or network.- Tests:
createTestApp()from@mainsdk/testingrunsdbon its in-memory fake, andchaos.on("db", { outage: true })simulates the store going down. - Before you ship: run
npx mainsdk check --env prodlocally or in CI to confirm production no longer resolves to SQLite.
What MainSDK adds on top
- No query without an owner scope, on SQLite as on every driver.
- Personal fields carry a label; a field labelled
panis refused. - A repeated idempotency key on
createorupdatenever writes twice. - Production can't run on it:
mainsdk checkfails withMAIN-DATA-0030.
See Data and records for the full contract.
Limits and notes
- Local only. Setting
db.driver: sqlitefor production failsmainsdk checkwithMAIN-DATA-0030; setdb.drivertopostgres,neonorsupabasefor prod. - The SQLite driver comes with the db spec (phase 1).
- SQLite is not a regional store, so it does not prove your residency setup; test region routing against your real driver.
Swap to or from it
db:
driver: postgres # was sqliteFAQ
Can I use SQLite in production for a small app? No. The check refuses it with MAIN-DATA-0030, so every production app gets regional stores, backups and drills from a real provider.
Do my Prisma or Drizzle migrations work with it? The db spec pairs the SQLite local driver with Prisma and Drizzle adapters; how migrations run against the local file is not decided yet.
Next
Open questions
Was this page helpful?