Skip to content

TypeDBLiteInterpreter

Defined in: libs/runtime/src/interpreter.ts:657

The engine: executes TypeQLite against SQLite. Open a database with new TypeDBLiteInterpreter(path), define a schema, then execute writes and query reads.

Deliberately an interpreter, not a SQL generator: bindings are resolved by executing, so a failing statement can say which one it was and a constraint violation knows which attribute it was writing. That last point is not a nicety — see translateConstraintError.

Constructors

Name Description
new TypeDBLiteInterpreter() Opens a database, creating it if it does not exist.

Properties

Name Description
changeLog The change log, which records every committed write as a revision (ADR-003 D1).

Accessors

Name Description
hasSchema Whether a schema has been applied — to THIS database, not this process.

Methods

Name Description
attributesOf() Every attribute of the given type that the thing with this iid owns, as attribute cells: the driver’s getHas.
attributeValueType() The value type an attribute type holds, through its parents — what a driver reads off the schema.
beginTransaction() Open a caller-held transaction: BEGIN IMMEDIATE, the write lock up front, for the reason applySchemaDdl gives (a deferred transaction that upgrades while another process holds the lock gets SQLITE_BUSY at once, and busy_timeout does not apply to an upgrade).
close() Closes the database.
commitTransaction() Commit — after what TypeDB checks at commit, which no single statement could: a relation left with no player is removed, and the schema and data must stand as a whole (validateCommit).
define() Apply a schema: its define, redefine and undefine clauses, checked against the data already stored.
execute() Run a write pipeline: insert, put, or delete, optionally preceded by a match.
lastQueryTrace() The counts of the most recent query(), or undefined when tracing is off.
query() Run a read pipeline and project its select — or, when it ends in fetch, answer one JSON document per answer in documents (fetch.feature), with rows empty.
rollbackTransaction() Roll back the transaction beginTransaction opened.
schemaSnapshot() The schema applied to this database, as sorted lists.
thingNumbered() The thing TypeDB would number <kind>:<type id>:<object id> (iid:entity:0:1): the objectth thing of exactly the typeth type of that kind.

new TypeDBLiteInterpreter(location?, busyTimeoutMs?, options?): TypeDBLiteInterpreter

Defined in: libs/runtime/src/interpreter.ts:725

Opens a database, creating it if it does not exist.

string = ':memory:'

:memory: for a database that lives only in this object, or the path of a SQLite file, which is also what openDatabase in options is given.

number = 5000

How long a write waits for another writer’s lock before failing with SQLITE_BUSY. Default 5000.

TypeDBLiteOptions = {}

Tracing, join planning, and which SQLite binding to open the database with.

TypeDBLiteInterpreter

readonly changeLog: ChangeLog

Defined in: libs/runtime/src/interpreter.ts:686

The change log, which records every committed write as a revision (ADR-003 D1). Its rows are written inside execute’s existing transaction, so a write and its log entry commit or roll back together — never a commit followed by a publish that a crash can lose.

get hasSchema(): boolean

Defined in: libs/runtime/src/interpreter.ts:879

Whether a schema has been applied — to THIS database, not this process.

boolean

attributesOf(iid, attribute): readonly TypeDBLiteValue[]

Defined in: libs/runtime/src/interpreter.ts:5422

Every attribute of the given type that the thing with this iid owns, as attribute cells: the driver’s getHas. Read the thing’s own attributes through this rather than trusting anything a cell carries.

number

string

readonly TypeDBLiteValue[]


attributeValueType(attribute): string | undefined

Defined in: libs/runtime/src/interpreter.ts:5414

The value type an attribute type holds, through its parents — what a driver reads off the schema.

string

string | undefined


beginTransaction(): void

Defined in: libs/runtime/src/interpreter.ts:2809

Open a caller-held transaction: BEGIN IMMEDIATE, the write lock up front, for the reason applySchemaDdl gives (a deferred transaction that upgrades while another process holds the lock gets SQLITE_BUSY at once, and busy_timeout does not apply to an upgrade).

void


close(): void

Defined in: libs/runtime/src/interpreter.ts:2929

Closes the database. The interpreter cannot be used afterwards.

void


commitTransaction(): void

Defined in: libs/runtime/src/interpreter.ts:2822

Commit — after what TypeDB checks at commit, which no single statement could: a relation left with no player is removed, and the schema and data must stand as a whole (validateCommit). A commit that fails rolls the whole transaction back, as TypeDB’s does.

void


define(text): ExecutionReport

Defined in: libs/runtime/src/interpreter.ts:1218

Apply a schema: its define, redefine and undefine clauses, checked against the data already stored. Re-applying is normal — a projector replays, and IF NOT EXISTS carries it.

string

ExecutionReport


execute(text, given?): WriteReport

Defined in: libs/runtime/src/interpreter.ts:1490

Run a write pipeline: insert, put, or delete, optionally preceded by a match.

string

GivenRows

WriteReport


lastQueryTrace(): Readonly<QueryTrace> | undefined

Defined in: libs/runtime/src/interpreter.ts:1616

The counts of the most recent query(), or undefined when tracing is off.

Readonly<QueryTrace> | undefined


query(text, given?): object

Defined in: libs/runtime/src/interpreter.ts:1661

Run a read pipeline and project its select — or, when it ends in fetch, answer one JSON document per answer in documents (fetch.feature), with rows empty.

string

GivenRows

object

diagnostics: readonly Diagnostic[]

optional documents?: JsonValue[]

rows: Record<string, TypeDBLiteValue>[]


rollbackTransaction(): void

Defined in: libs/runtime/src/interpreter.ts:2916

Roll back the transaction beginTransaction opened. Never throws: a rollback that fails after the engine already ended the transaction is moot.

void


schemaSnapshot(): TypeDBLiteSchemaSnapshot

Defined in: libs/runtime/src/interpreter.ts:884

The schema applied to this database, as sorted lists. Survives a reopen.

TypeDBLiteSchemaSnapshot


thingNumbered(kind, type, object): number | undefined

Defined in: libs/runtime/src/interpreter.ts:5434

The thing TypeDB would number <kind>:<type id>:<object id> (iid:entity:0:1): the objectth thing of exactly the typeth type of that kind. TypeDB allocates a type id per kind, in definition order, and an object id per type, in creation order. Returns undefined when there is no such thing.

TypeDB never reuses an object id, and a deleted thing leaves no row here, so after a delete the numbering of later things in the type shifts down.

"entity" | "relation"

number

number

number | undefined

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.