Skip to content

SqliteEngine

Defined in: libs/runtime/src/sqlite-engine.ts:29

A SQLite engine behind TypeDBLiteDatabase’s five methods.

Async throughout because the port is, not because SQLite is: node:sqlite is synchronous, and pretending otherwise here would be the only honest place to hide a future async engine.

Constructors

Name Description
new SqliteEngine() Opens a database and an interpreter over it.

Accessors

Name Description
changeLog This engine’s change log.
hasSchema Whether a schema has been applied to this database — survives a reopen.

Methods

Name Description
close() Closes the database.
define() Applies schema definitions: the define of the interpreter.
execute() Runs a pipeline for its effect and returns the execution report.
persist() A no-op, and TypeDBLiteDatabase.persist is documented as one so a caller can persist unconditionally after a write.
query() Runs a pipeline and returns its rows.
schemaSnapshot() The schema applied to this database, as sorted lists.
transaction() Run work in one transaction: BEGIN IMMEDIATE, then COMMIT if it resolves or ROLLBACK if it throws, rethrowing the same error.

new SqliteEngine(location?, options?): SqliteEngine

Defined in: libs/runtime/src/sqlite-engine.ts:38

Opens a database and an interpreter over it.

string = ':memory:'

:memory:, or the path of a SQLite file.

TypeDBLiteOptions = {}

How the interpreter opens the database and runs queries.

SqliteEngine

get changeLog(): ChangeLog

Defined in: libs/runtime/src/sqlite-engine.ts:53

This engine’s change log.

ChangeLog


get hasSchema(): boolean

Defined in: libs/runtime/src/sqlite-engine.ts:58

Whether a schema has been applied to this database — survives a reopen.

boolean

close(): Promise<void>

Defined in: libs/runtime/src/sqlite-engine.ts:123

Closes the database.

Promise<void>


define(schema): Promise<unknown>

Defined in: libs/runtime/src/sqlite-engine.ts:68

Applies schema definitions: the define of the interpreter. Safe to repeat.

string

Promise<unknown>


execute(query): Promise<unknown>

Defined in: libs/runtime/src/sqlite-engine.ts:73

Runs a pipeline for its effect and returns the execution report.

string

Promise<unknown>


persist(): Promise<void>

Defined in: libs/runtime/src/sqlite-engine.ts:92

A no-op, and TypeDBLiteDatabase.persist is documented as one so a caller can persist unconditionally after a write.

A file-backed SQLite database has already written by the time this is called: the interpreter commits each pipeline. There is no snapshot to take.

Promise<void>


query(query): Promise<{ rows: readonly EngineRow[]; }>

Defined in: libs/runtime/src/sqlite-engine.ts:81

Runs a pipeline and returns its rows.

string

Promise<{ rows: readonly EngineRow[]; }>


schemaSnapshot(): TypeDBLiteSchemaSnapshot

Defined in: libs/runtime/src/sqlite-engine.ts:63

The schema applied to this database, as sorted lists.

TypeDBLiteSchemaSnapshot


transaction<T>(work): Promise<T>

Defined in: libs/runtime/src/sqlite-engine.ts:104

Run work in one transaction: BEGIN IMMEDIATE, then COMMIT if it resolves or ROLLBACK if it throws, rethrowing the same error. Inside work, this engine’s own execute and query are in the transaction.

One handle, one transaction at a time. Two overlapping calls on the same engine would share one SQLite connection and so one transaction; TypeDBLiteDatabase serializes them, and a second BEGIN here is refused rather than silently joined.

T

() => Promise<T>

Promise<T>

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.