SqliteDatabase
Defined in: libs/runtime/src/sqlite-database.ts:80
The synchronous SQLite surface TypeDBLite’s interpreter runs against.
Measured 2026-10-22 over interpreter.ts, schema-mutation.ts, change-log.ts and full-text.ts: this is every
part of node:sqlite’s DatabaseSync they use, and nothing more. It exists so a second binding (a WASM SQLite in
a browser or a Capacitor WebView) can be handed to the interpreter without the interpreter importing node:sqlite.
Only node-sqlite.ts does.
Synchronous on purpose. About 250 call sites run a statement and use its result on the next line, inside transactions. An async binding (the Capacitor SQLite plugin crosses a native bridge, so every call is a Promise) does not satisfy this interface; it would mean making the interpreter async throughout. A binding that is synchronous inside a Web Worker does satisfy it.
What a binding must honor beyond the types:
- Bare named parameters.
.all({ id })and.run({ keep })bind:idand:keep— the object’s keys carry no prefix.node:sqliteallows this by default; most WASM bindings need the keys prefixed ({ ':id': id }), so an adapter must translate. - Positional parameters (
?) as spread arguments. - Rows are plain objects keyed by column name, and
INTEGERcolumns come back asnumber. - Errors carry SQLite’s own message text and a numeric
errcode.translateConstraintErrormatcheserrcode === 2067(SQLITE_CONSTRAINT_UNIQUE), and one catch matches/UNIQUE constraint failed/on the message. An adapter that throws a bare string or wraps the error without these silently turns a reported duplicate into an unreported one. run()reportschangesexactly — seeSqliteStatement.run.execruns more than one statement when given more than one (schema DDL does).- The pragmas the constructor sets (
busy_timeout,case_sensitive_like,journal_mode) must be accepted. A binding with no WAL (an in-memory or single-connection OPFS database) may report a different journal mode, which the engine already tolerates; it must not throw.
Member summary
Section titled “Member summary”Properties
| Name | Description |
|---|---|
| isTransaction? | Whether a transaction is open on this handle. |
Methods
| Name | Description |
|---|---|
| close() | Closes the connection. |
| exec() | Runs one or more statements that return nothing, such as schema DDL. |
| prepare() | Prepares a statement, which can then be run with positional or named parameters. |
Properties
Section titled “Properties”isTransaction?
Section titled “isTransaction?”
readonlyoptionalisTransaction?:boolean
Defined in: libs/runtime/src/sqlite-database.ts:91
Whether a transaction is open on this handle. Optional: node:sqlite has it from Node 22.16
and 24.0, and the interpreter treats its absence as “unknown”, not as “no”.
Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Defined in: libs/runtime/src/sqlite-database.ts:86
Closes the connection.
Returns
Section titled “Returns”void
exec()
Section titled “exec()”exec(
sql):void
Defined in: libs/runtime/src/sqlite-database.ts:82
Runs one or more statements that return nothing, such as schema DDL.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
prepare()
Section titled “prepare()”prepare(
sql):SqliteStatement
Defined in: libs/runtime/src/sqlite-database.ts:84
Prepares a statement, which can then be run with positional or named parameters.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”TypeDBLite is an independent open-source project, built on TypeDB with thanks. It is not affiliated with, sponsored by, or endorsed by TypeDB Ltd. Released under the MPL-2.0 license.