TinyJoinDialect
The TinyJoinDialect class is a Kysely dialect that runs Kysely's PostgreSQL queries on a TinyJoin Client.
Kysely runs one query at a time on the Client, so a query outside a transaction waits until the transaction ends rather than failing. Kysely's db.transaction runs on the Client's callback transaction, which holds the database, and every tab sharing it, until it commits or rolls back. It takes no isolation level or access mode, and there are no savepoints.
Its introspector reads the Client's getSchema, and Kysely's Migrator runs each migration's statements in turn, since TinyJoin runs DDL outside transactions, with a Web Lock keeping one tab migrating at a time.
Example
import {create} from 'tinyjoin';
import {TinyJoinDialect} from 'tinyjoin/kysely';
import {Kysely} from 'kysely';
interface Database {
tasks: {id: string; title: string; done: boolean};
}
const client = await create('opfs://my-app-v1');
const db = new Kysely<Database>({dialect: new TinyJoinDialect({client})});
const open = await db
.selectFrom('tasks')
.select(['id', 'title'])
.where('done', '=', false)
.execute();
Since
v0.5.0