tinyjoin
v0.3.0
Published
A tiny, worker-first relational database for browser apps.
Maintainers
Readme
> npm create tinyjoin@latest
🎉 Welcome to TinyJoin!
📦 Creating your project...npm install tinyjoinimport {create} from 'tinyjoin';
const db = await create('opfs://my-app');await db.exec(`
CREATE TABLE IF NOT EXISTS tasks (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
done BOOLEAN NOT NULL DEFAULT false
)
`);const id = crypto.randomUUID();
await db.query(
'INSERT INTO tasks (id, title) VALUES ($1, $2)',
[id, 'Try TinyJoin'],
);const title = 'Written with a tag';
await db.sql`
INSERT INTO tasks (id, title)
VALUES (${crypto.randomUUID()}, ${title})
`;type Task = {id: string; title: string};
const {rows} = await db.query<Task>(
'SELECT id, title FROM tasks ORDER BY title',
);await db.transaction(async (tx) => {
await tx.query(
'UPDATE tasks SET done = $1 WHERE id = $2',
[true, id],
);
await tx.query(
'DELETE FROM tasks WHERE done = $1',
[true],
);
});const openTasks = await db.prepare<{
id: string;
title: string;
}>('SELECT id, title FROM tasks WHERE done = $1');
const {rows} = await openTasks.execute([false]);const unsubscribe = db.subscribe(
{tables: ['tasks']},
() => render(),
);
// Later
unsubscribe();
await db.close();