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.
Member summary
Section titled “Member summary”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. |
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TypeDBLiteInterpreter(
location?,busyTimeoutMs?,options?):TypeDBLiteInterpreter
Defined in: libs/runtime/src/interpreter.ts:725
Opens a database, creating it if it does not exist.
Parameters
Section titled “Parameters”location?
Section titled “location?”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.
busyTimeoutMs?
Section titled “busyTimeoutMs?”number = 5000
How long a write waits for another writer’s lock before failing with SQLITE_BUSY. Default 5000.
options?
Section titled “options?”TypeDBLiteOptions = {}
Tracing, join planning, and which SQLite binding to open the database with.
Returns
Section titled “Returns”TypeDBLiteInterpreter
Properties
Section titled “Properties”changeLog
Section titled “changeLog”
readonlychangeLog: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.
Accessors
Section titled “Accessors”hasSchema
Section titled “hasSchema”Get Signature
Section titled “Get Signature”get hasSchema():
boolean
Defined in: libs/runtime/src/interpreter.ts:879
Whether a schema has been applied — to THIS database, not this process.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”attributesOf()
Section titled “attributesOf()”attributesOf(
iid,attribute): readonlyTypeDBLiteValue[]
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.
Parameters
Section titled “Parameters”number
attribute
Section titled “attribute”string
Returns
Section titled “Returns”readonly TypeDBLiteValue[]
attributeValueType()
Section titled “attributeValueType()”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.
Parameters
Section titled “Parameters”attribute
Section titled “attribute”string
Returns
Section titled “Returns”string | undefined
beginTransaction()
Section titled “beginTransaction()”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).
Returns
Section titled “Returns”void
close()
Section titled “close()”close():
void
Defined in: libs/runtime/src/interpreter.ts:2929
Closes the database. The interpreter cannot be used afterwards.
Returns
Section titled “Returns”void
commitTransaction()
Section titled “commitTransaction()”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.
Returns
Section titled “Returns”void
define()
Section titled “define()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”execute()
Section titled “execute()”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.
Parameters
Section titled “Parameters”string
given?
Section titled “given?”Returns
Section titled “Returns”lastQueryTrace()
Section titled “lastQueryTrace()”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.
Returns
Section titled “Returns”Readonly<QueryTrace> | undefined
query()
Section titled “query()”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.
Parameters
Section titled “Parameters”string
given?
Section titled “given?”Returns
Section titled “Returns”object
diagnostics
Section titled “diagnostics”diagnostics: readonly
Diagnostic[]
documents?
Section titled “documents?”
optionaldocuments?:JsonValue[]
rows:
Record<string,TypeDBLiteValue>[]
rollbackTransaction()
Section titled “rollbackTransaction()”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.
Returns
Section titled “Returns”void
schemaSnapshot()
Section titled “schemaSnapshot()”schemaSnapshot():
TypeDBLiteSchemaSnapshot
Defined in: libs/runtime/src/interpreter.ts:884
The schema applied to this database, as sorted lists. Survives a reopen.
Returns
Section titled “Returns”thingNumbered()
Section titled “thingNumbered()”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.
Parameters
Section titled “Parameters”"entity" | "relation"
number
object
Section titled “object”number
Returns
Section titled “Returns”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.