Field Types
Complete reference for all field.* builder types and chainable modifiers.
Field Types
Complete reference for the field.* builder API.
Core types
Semantic types
These map to underlying column types but also configure model validation and hooks:
Modifiers (chainable)
All modifiers return the same FieldDefinition and can chain in any order:
ts
// Column constraints
.required() // .notNull()
.optional() // removes .notNull()
.unique() // .unique()
.primaryKey() // .primaryKey()
.default(value) // .default(value)
.defaultRandom() // .defaultRandom() — for uuid PKs
.references(col) // foreign key — 'table.column'
// String-specific
.minLength(n) // Zod .min(n)
.maxLength(n) // Zod .max(n)
// Password-specific
.requireUppercase() // Zod custom validation
.requireNumbers() // Zod custom validation
.hash() // bcrypt on create/update
// Number-specific
.min(n)
.max(n)
.positive()
.integer() // Zod .int()Examples
ts
// UUID primary key
id: field.uuid().primaryKey().defaultRandom(),
// Required varchar with unique constraint
email: field.email().required().unique(),
// Auto-hashed password
password: field.password().required().minLength(8).hash(),
// Enum with default
role: field.enum('user', 'admin', 'moderator').default('user'),
// Foreign key
authorId: field.uuid().required().references('users.id'),
// Optional rich text
bio: field.richtext().optional(),
// JSON blob
metadata: field.json().optional(),