/** * Local sync database. * * This is the single instance every component reads from and writes to. Under * the hood it's a SQLite database running in the browser (via WASM) that * mirrors a subset of the server-side Postgres tables. Reads are local and * synchronous-fast; writes go to the local DB first and are streamed to the * server in the background by the connector. * * The schema here MUST match the columns declared in `schema.ts`. The local * engine refuses to materialise rows whose columns it doesn't know about. */ import { PowerSyncDatabase } from '@powersync/web'; import { appSchema } from './schema'; export const db = new PowerSyncDatabase({ schema: appSchema, // `database.dbFilename` is the IndexedDB key used to persist the local // SQLite file across reloads. Each app gets its own — namespaced by app // name to avoid collisions when multiple apps run on the same origin // during development. database: { dbFilename: '{{APP_NAME}}.db' }, });