Low-Level Types
Low-level types give you direct control over SQL column types when semantic types don’t fit your needs.
Type Reference
Section titled “Type Reference”| Type | SQL Result | Notes |
|---|---|---|
col.string(n) | VARCHAR(n) | Fixed-length string |
col.text() | TEXT | Unlimited length |
col.integer() | INTEGER | 32-bit integer |
col.float() | FLOAT | Floating point |
col.decimal(p,s) | DECIMAL | Precise decimal |
col.boolean() | BOOLEAN | True/false |
col.date() | DATE | Date only |
col.time() | TIME | Time only |
col.datetime() | TIMESTAMP | Date and time |
col.uuid() | UUID | Unique identifier |
col.json() | JSONB | JSON data |
col.base64() | TEXT | Base64 encoded |
col.enum([...]) | CHECK | Constrained values |
Examples
Section titled “Examples”Strings
Section titled “Strings”export default table({ id: col.id(), sku: col.string(50).unique(), // VARCHAR(50) description: col.text().optional(), // TEXT, nullable});Numbers
Section titled “Numbers”export default table({ id: col.id(), amount: col.decimal(10, 2), // DECIMAL(10,2) count: col.integer(), // INTEGER rate: col.float(), // FLOAT});Dates and Times
Section titled “Dates and Times”export default table({ id: col.id(), event_date: col.date(), // DATE start_time: col.time(), // TIME created_at: col.datetime(), // TIMESTAMP});JSON and UUID
Section titled “JSON and UUID”export default table({ id: col.uuid(), // UUID (use col.id() for primary key) user: col.belongs_to("auth.user"), preferences: col.json(), // JSONB});export default table({ id: col.id(), status: col .enum(["pending", "processing", "shipped", "delivered"]) .default("pending"), priority: col.enum(["low", "normal", "high"]).default("normal"),}).timestamps();Prefer Semantic Types
Section titled “Prefer Semantic Types”For most cases, use semantic types instead - they include validation and sensible defaults:
| Instead of… | Use… |
|---|---|
col.string(255) | col.email() |
col.string(100) | col.name() |
col.integer() | col.quantity() |
col.decimal(19,4) | col.money() |
col.boolean() | col.flag() |
See Semantic Types for the full list.