push

The push function makes the database hold the tables of a Drizzle schema, as Drizzle Kit's push would for PostgreSQL, but from the application and as one change that commits whole or not at all.

push<TSchema>(
  db: TinyJoinDatabase<TSchema>,
  schema: Record<string, unknown>,
  options?: PushOptions,
): Promise<boolean>
TypeDescription
dbTinyJoinDatabase<TSchema>

The Drizzle database, from drizzle.

schemaRecord<string, unknown>

The Drizzle schema, whose tables push reads, leaving out its relations.

options?PushOptions

The schema's version, whether to drop what it leaves out, and what it renames.

returnsPromise<boolean>

A Promise resolving to true if the database changed, or false if it already held the schema.

It reads each table's columns, primary key, unique constraints, and indexes from Drizzle, and passes them to the Client's setSchema, which creates what the database lacks and changes what differs. A schema the database already holds changes nothing, so every tab of an application can call push as it starts, in place of migrations.

A table that declares what TinyJoin does not have, such as a foreign key, a timestamp column, an SQL default, or an index on an expression, is refused before anything changes. A default Drizzle works out in JavaScript, with $defaultFn, is Drizzle's, not the database's.

Example

import {create} from 'tinyjoin';
import {drizzle, push} from 'tinyjoin/drizzle';
import * as schema from './schema';

const db = drizzle(await create('opfs://my-app-v1'), {schema});
await push(db, schema, {version: 2, renames: {'tasks.name': 'title'}});