create
The create function opens a TinyJoin database in a dedicated Worker.
create(): Promise<Client>| returns | Promise<Client> | A Promise resolving to a |
|---|
This overload creates an ephemeral in-memory database using the packaged Worker. Its data is lost when the Client closes or the page reloads.
Example
import {create} from 'tinyjoin';
const db = await create();
await db.exec(`
CREATE TABLE IF NOT EXISTS tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL
)
`);
const {rows} = await db.query('SELECT * FROM tasks ORDER BY id');
await db.close();
Since
v0.0.5
This create overload opens a database with ClientOptions.
create(options: ClientOptions): Promise<Client>| Type | Description | |
|---|---|---|
options | ClientOptions | Storage and Worker configuration. |
| returns | Promise<Client> | A Promise resolving to a |
Use the options object to select storage or provide a custom Worker. Omitting its dataDir property selects an ephemeral in-memory database.
Example
import {create} from 'tinyjoin';
const db = await create({dataDir: 'memory://'});
await db.close();
Since
v0.0.5
This create overload opens a database at the supplied storage URL.
create(
dataDir: string | undefined,
options?: ClientOptions,
): Promise<Client>| Type | Description | |
|---|---|---|
dataDir | string | undefined | The |
options? | ClientOptions | Optional Worker configuration. |
| returns | Promise<Client> | A Promise resolving to a |
Use a stable opfs://name to persist data in the same browser, or memory:// for an ephemeral database. When providing the second argument, supply a storage URL and leave options.dataDir unset.
Example
import {create} from 'tinyjoin';
const db = await create('opfs://my-app');
await db.close();
Since
v0.0.5