Skip to content

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 :id and :keep — the object’s keys carry no prefix. node:sqlite allows 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 INTEGER columns come back as number.
  • Errors carry SQLite’s own message text and a numeric errcode. translateConstraintError matches errcode === 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() reports changes exactly — see SqliteStatement.run.
  • exec runs 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.

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.

readonly optional isTransaction?: 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”.

close(): void

Defined in: libs/runtime/src/sqlite-database.ts:86

Closes the connection.

void


exec(sql): void

Defined in: libs/runtime/src/sqlite-database.ts:82

Runs one or more statements that return nothing, such as schema DDL.

string

void


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.

string

SqliteStatement

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.