Getting started
This guide takes you from a fresh clone to running a schema and queries, first from the command line and then from your own code. It takes about ten minutes.
Prerequisites
Section titled “Prerequisites”- Node.js 22.16 or later. TypeDBLite uses
node:sqlite, which is built into Node, and needs its full-text search (FTS5), which Node’s bundled SQLite includes from 22.16. Older releases either have nonode:sqlite(22.12) or lack FTS5 (22.13 to 22.15). Node 24 is what the project is developed on. - npm, which comes with Node. The repository is an npm workspace.
- Linux, macOS or Windows. CI builds and tests on all three.
- git.
You do not need a native toolchain, Docker, or a TypeDB server.
Build from source
Section titled “Build from source”git clone https://github.com/typedblite/typedblite.gitcd typedblitenpm installnpm run buildnpm run build builds every package in dependency order through Nx. The language
package generates its parser from the grammar first, so the first build takes a little longer.
To check that everything works, run the test suites:
npm testYour first session in the CLI
Section titled “Your first session in the CLI”The CLI is at apps/cli/out/main.js.
1. Write a schema and some data
Section titled “1. Write a schema and some data”Save this as people.tql:
# The schemadefine entity person, owns name @key, plays employment:employee; entity company, owns name @key, plays employment:employer; relation employment, relates employee, relates employer; attribute name, value string;
# Some datainsert $a isa person, has name "Alice";insert $b isa person, has name "Bob";insert $c isa company, has name "Acme";
match $a isa person, has name "Alice"; $c isa company, has name "Acme";insert (employee: $a, employer: $c) isa employment;2. Load it into a database file
Section titled “2. Load it into a database file”node apps/cli/out/main.js --file people.tql --database ./people.dbschema appliedokokokok--database names a SQLite file, which persists between runs. Without it, the CLI uses an
in-memory database that is gone when the command ends.
3. Query it
Section titled “3. Query it”Start the REPL against the same file:
node apps/cli/out/main.js --repl --database ./people.dbmatch (employee: $p, employer: $c) isa employment; $p has name $person; $c has name $company; select $person, $company;person=Alice company=Acme(1 row)Who is not employed anywhere?
match $p isa person, has name $n; not { (employee: $p) isa employment; }; select $n;n=Bob(1 row)Type .exit (or press Ctrl-D) to leave. To run one statement without the REPL, use --exec:
node apps/cli/out/main.js --exec 'match $p isa person, has name $n; select $n;' --database ./people.dbCLI tip. The CLI decides where a statement ends by looking at
;. Adefineblock or amatch … insert …pipeline may span several lines in a--file. In the REPL, type adefineblock on one line, and write a standaloneinsertas oneinsertper thing, as above. The engine API (next section) has neither restriction. The CLI README has the full reference.
Your first program
Section titled “Your first program”The same steps from TypeScript. TypeDBLiteInterpreter is the engine. It is synchronous, because
node:sqlite is:
import { TypeDBLiteInterpreter } from '@typedblite/runtime';
const db = new TypeDBLiteInterpreter(':memory:'); // or a file path, such as './people.db'
db.define(` define entity person, owns name @key, owns email; attribute name, value string; attribute email, value string;`);
db.execute(`insert $p isa person, has name "Alice", has email "alice@example.com";`);
const { rows } = db.query(`match $p isa person, has name $n, has email $e; select $n, $e;`);
for (const row of rows) { console.log(row.n.asString(), row.e.asString()); // Alice alice@example.com}
db.close();If your code expects an asynchronous database, SqliteEngine wraps the same engine in async
methods and adds a transaction helper. See
Embedding the runtime.
Each value in a row is a TypeDBLiteValue, a concept such as an entity, a relation, an attribute
or a computed value. Call asString(), asInteger() or asDouble() to read an attribute or value
cell. See Embedding the runtime.
Nothing is on npm yet. Once the first release is out, the runtime installs with:
npm install @typedblite/runtimeUntil then, build from source and depend on the workspace packages. What a version number will promise is in Versions and compatibility.
When something is refused
Section titled “When something is refused”TypeDBLite never silently ignores something it does not support. A statement it cannot run fails with an error that carries a structured diagnostic:
import { diagnosticOf, DiagnosticCode } from '@typedblite/runtime';
try { db.query(`match $x isa planet; select $x;`);} catch (error) { const diagnostic = diagnosticOf(error); diagnostic?.code === DiagnosticCode.unknownType; // true // "Unknown type 'planet': type label 'planet' not found. The applied schema defines: person"}Edit TypeQLite with the VS Code extension
Section titled “Edit TypeQLite with the VS Code extension”The repository includes a TypeQLite editor for .tql and .typeqlite files. To build and install
it:
npm exec nx -- run typeqlite-vscode:packagecode --install-extension apps/vscode/dist/typeqlite-0.0.1.vsixNext steps
Section titled “Next steps”- Five-minute tour: a notebook, the command line and a small program on one SQLite file, from an empty folder (for after the first release, when it installs from npm).
- Embedding the runtime: the whole engine API.
- The TypeQLite language: everything you can write.
- Replication and search: syncing stores, and full-text search.
- Contributing: if you want to change TypeDBLite itself.
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.