drizzle

The drizzle function creates a Drizzle database over a TinyJoin Client.

drizzle<TSchema>(
  client: Client,
  config?: DrizzleConfig<TSchema>,
): TinyJoinDatabase<TSchema>
TypeDescription
clientClient

The TinyJoin Client to query, from create().

config?DrizzleConfig<TSchema>

Drizzle's configuration: its schema, for relational queries, and its logger, casing, and cache.

returnsTinyJoinDatabase<TSchema>

A Drizzle database.

Queries run on the Client as array rows, which Drizzle maps to its own result shapes. Drizzle's db.transaction runs on the Client's callback transaction, so it holds the database as any TinyJoin transaction does, tx.rollback discards its work, and a transaction cannot nest, since there are no savepoints, or take an isolation level.

A value Drizzle encodes for a json or jsonb column is bound as the JSON value it is, rather than as the JSON text Drizzle makes of it, which TinyJoin would store as a string.

Close the Client yourself when the database is no longer needed.

Example

import {create} from 'tinyjoin';
import {drizzle} from 'tinyjoin/drizzle';
import {eq} from 'drizzle-orm';
import {boolean, pgTable, text} from 'drizzle-orm/pg-core';

const tasks = pgTable('tasks', {
  id: text('id').primaryKey(),
  title: text('title').notNull(),
  done: boolean('done').notNull().default(false),
});

const client = await create('opfs://my-app-v1');
const db = drizzle(client, {schema: {tasks}});
await db.insert(tasks).values({id: crypto.randomUUID(), title: 'Try Drizzle'});
const open = await db.select().from(tasks).where(eq(tasks.done, false));