vertz/db is the database layer of the Vertz stack. You define schemas with the d builder, query with typed operations, and run migrations with a single command. Types are inferred from your schema — no code generation step, no separate type files.
How it works
Define your schema
Use the
d builder to declare tables, columns, and relations. Column types, constraints, and
annotations are all defined in TypeScript.Query with types
The database client provides typed CRUD operations. Filters, selects, and includes are all
type-checked at compile time.
Quick example
db.users.create() only accepts fields from the table definition, and the return type includes all non-hidden columns.
Database support
All databases use the samecreateDb() API — the only difference is the options you pass:
| Option | PostgreSQL | SQLite (local) | Cloudflare D1 |
|---|---|---|---|
dialect | 'postgres' (default) | 'sqlite' | 'sqlite' |
| Connection | url: string | path: string | d1: D1Database |
| Migrations | CLI (vertz db migrate) | migrations: { autoApply: true } | Not available (autoApply is disallowed for D1 — use wrangler migrations) |
| Transactions | db.transaction() | db.transaction() | Not supported (use D1Database.batch()) |
SQLite with
autoApply: true automatically creates tables on first query — no migration commands
needed during development. Boolean values are stored as 0/1 and timestamps as ISO strings, but
the query layer converts them to native JS types automatically.What’s included
| Feature | Description |
|---|---|
| Schema builder | Declarative d API for tables, columns, relations |
| Typed queries | CRUD operations with compile-time type checking |
| Automatic migrations | Schema diffing with CLI commands |
| Multi-dialect | PostgreSQL and SQLite with a unified API |
| Relations | One-to-many, many-to-one, many-to-many through join tables |
| Transactions | Atomic multi-operation writes with db.transaction() |
| Error handling | Result-based errors — never throws |
| Multi-tenancy | Built-in tenant scoping at the model level |
Core principles
Schema is the source of truth
Column types, constraints, defaults, and annotations are all declared in the schema. Input/output types, validation schemas, and migration diffs are derived from it automatically. No duplication.Result-based errors
Query operations returnResult<T, Error> — they never throw. You handle errors explicitly with pattern matching, not try/catch:
Compile-time safety
If your schema saysrole is an enum of 'admin' | 'user', the query builder rejects any other value at compile time. If a column is .readOnly(), it won’t appear in create/update input types. The TypeScript compiler catches data issues before they reach the database.
Guides
Schema
Tables, columns, types, relations, and annotations.
Queries
CRUD operations, filters, pagination, and error handling.
Migrations
Auto-migration CLI and deployment workflow.
Seeding
Populate your database with dev, test, and production data.