Type Alias: Lix

Lix = { call: (name: string, payload?: unknown, opts?: { signal?: AbortSignal; }) => Promise<unknown>; close: () => Promise<void>; db: Kysely<LixDatabaseSchema>; engine?: LixEngine; hooks: LixHooks; observe: ReturnType<typeof createObserve>; plugin: { getAll: () => Promise<LixPlugin[]>; }; toBlob: () => Promise<Blob>; }

Properties

call()

call: (name: string, payload?: unknown, opts?: { signal?: AbortSignal; }) => Promise<unknown>

Calls a named engine function and returns its result.

Preferred entrypoint for invoking engine functions.

Parameters

ParameterType
namestring
payload?unknown
opts?{ signal?: AbortSignal; }
opts.signal?AbortSignal

Returns

Promise<unknown>


close()

close: () => Promise<void>

Closes the lix instance and its storage.

Returns

Promise<void>


db

db: Kysely<LixDatabaseSchema>


engine?

optional engine: LixEngine

In‑process engine context bound to the live database.

When Lix runs in‑process (same thread as the database), engine is available and tests can directly call helpers that accept { engine }.

When Lix runs out‑of‑process (for example inside a Worker), the engine is not accessible from the main thread and will be undefined. In those environments, use lix.call to invoke engine functions across the boundary.

Guidance:

  • Prefer lix.db for normal queries and lix.call for engine operations. Reserve lix.engine for unit tests or internal SDK code that explicitly requires in‑process access alongside the database.
  • Do not rely on lix.engine in application/business logic, since it may be undefined in worker/remote environments.

Unit test in the same process

Examples

test("example test", async () => {
  // InMemory environment runs in the same process (in‑process engine).
  const lix = await openLix({
     environment: new InMemoryenvironment()
  });
  executeSync({
    engine: lix.engine!,
    data: [...],
  });
});

Worker/remote environment – prefer router calls

await lix.call("lix_insert_transaction_state", { timestamp, data });

hooks

hooks: LixHooks

Hooks for listening to database lifecycle events.

Allows registering callbacks that fire at specific points in Lix's execution, such as when state changes are committed.


observe

observe: ReturnType<typeof createObserve>


plugin

plugin: { getAll: () => Promise<LixPlugin[]>; }

getAll()

getAll: () => Promise<LixPlugin[]>

Returns

Promise<LixPlugin[]>


toBlob()

toBlob: () => Promise<Blob>

Serialises the Lix into a Blob.

Use this helper to persist the current state to disk or send it to a server. The blob contains the raw SQLite file representing the Lix project.

Example

const blob = await lix.toBlob()
download(blob)

Returns

Promise<Blob>