TinyJoin logoTinyJoin

create

The create function opens a fresh in-memory database in a dedicated Node Worker thread. It resolves when the database is ready.

create(dataDir?: "memory://"): Promise<Client>
TypeDescription
dataDir?"memory://"

The optional memory:// URL.

returnsPromise<Client>

A ready Client. Always await its close method when finished.

Omit the argument or pass memory://. Each call owns an independent database and Worker; close the Client to release the Worker. All data is lost when the Client closes or the process exits. OPFS, filesystem persistence, and remote synchronization are not supported by this entry point.

Example

import {type Client, create} from 'tinyjoin/node';

const db: Client = await create();
try {
  await db.exec('CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT)');
  await db.query('INSERT INTO notes VALUES ($1, $2)', [1, 'Hello from Node']);
  console.log((await db.query('SELECT * FROM notes ORDER BY id')).rows);
} finally {
  await db.close();
}

Since

v0.1.0