Skip to content
Built with

Database and Seeding ​

SDK Reference

Imported from "void/db". db is a Drizzle ORM instance for your database. The default is Cloudflare D1. Use "database": "pg" for PostgreSQL or "database": "mysql" for MySQL.

On this pageQuery your database with db · Seed data for development · Check dialect-specific details

db ​

The default Drizzle instance, already connected to your schema in db/schema.ts.

ts
import { users } from '@schema';
import { db } from 'void/db';

const allUsers = await db.select().from(users).all();

db uses your configured dialect and schema.

  • D1 projects resolve the DB binding and expose DrizzleD1Database<Schema>.
  • PostgreSQL projects use DATABASE_URL in local dev and Hyperdrive's connectionString in production. They expose NodePgDatabase<Schema>.
  • MySQL projects use the same connection sources. They expose MySql2Database<Schema>.

createDb(database) ​

Creates a Drizzle instance for the active dialect.

For D1 projects, pass a D1 binding. Use this when you have several D1 databases or need a binding other than the default.

ts
import { env } from 'cloudflare:workers';
import { createDb } from 'void/db';

const db = createDb(env.MY_OTHER_DB);

For PostgreSQL and MySQL projects, pass a connection string.

ts
import { createDb } from 'void/db';

const db = createDb('postgres://user:password@host:5432/app');

Signature:

ts
// D1
function createDb(d1: D1Database): DrizzleD1Database<Schema>;

// PostgreSQL
function createDb(connectionString: string): NodePgDatabase<Schema>;

// MySQL
function createDb(connectionString: string): MySql2Database<Schema>;

Query Operators ​

void/db re-exports common Drizzle operators. You never need drizzle-orm as a direct dependency:

ts
import { db, eq, and, or, desc, like, inArray, sql } from 'void/db';

Full list: sql, eq, ne, gt, gte, lt, lte, and, or, not, desc, asc, like, ilike, notLike, inArray, notInArray, isNull, isNotNull, between, notBetween, exists, notExists, count, sum, avg, min, max.

Seeding ​

Imported from "void/seed".

defineSeed(fn) ​

An identity helper for seed modules that void db seed runs.

ts
import { defineSeed } from 'void/seed';

export default defineSeed<typeof import('./schema')>(async ({ db, schema }) => {
  await db.insert(schema.users).values([
    { name: 'Alice', email: 'alice@example.com' },
    { name: 'Bob', email: 'bob@example.com' },
  ]);
});

The callback receives:

  • dialect: "sqlite", "postgresql" or "mysql"
  • db: a local Drizzle instance for the active dialect
  • schema: the exports from db/schema.ts or db/schema/

A seed module can export default or a named seed function.

Next steps ​

implemented.stream AI