Skip to content

Low-Level Types

Low-level types give you direct control over SQL column types when semantic types don’t fit your needs.

TypeSQL ResultNotes
col.string(n)VARCHAR(n)Fixed-length string
col.text()TEXTUnlimited length
col.integer()INTEGER32-bit integer
col.float()FLOATFloating point
col.decimal(p,s)DECIMALPrecise decimal
col.boolean()BOOLEANTrue/false
col.date()DATEDate only
col.time()TIMETime only
col.datetime()TIMESTAMPDate and time
col.uuid()UUIDUnique identifier
col.json()JSONBJSON data
col.base64()TEXTBase64 encoded
col.enum([...])CHECKConstrained values
schemas/catalog/product.js
export default table({
id: col.id(),
sku: col.string(50).unique(), // VARCHAR(50)
description: col.text().optional(), // TEXT, nullable
});
schemas/finance/transaction.js
export default table({
id: col.id(),
amount: col.decimal(10, 2), // DECIMAL(10,2)
count: col.integer(), // INTEGER
rate: col.float(), // FLOAT
});
schemas/calendar/event.js
export default table({
id: col.id(),
event_date: col.date(), // DATE
start_time: col.time(), // TIME
created_at: col.datetime(), // TIMESTAMP
});
schemas/core/settings.js
export default table({
id: col.uuid(), // UUID (use col.id() for primary key)
user: col.belongs_to("auth.user"),
preferences: col.json(), // JSONB
});
schemas/orders/order.js
export default table({
id: col.id(),
status: col
.enum(["pending", "processing", "shipped", "delivered"])
.default("pending"),
priority: col.enum(["low", "normal", "high"]).default("normal"),
}).timestamps();

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.