Skip to content

Field types

Use t.* to define field types. Each type returns a FieldChain with chainable modifiers.

Type Description
t.string(length?) String with optional length
t.uuid() UUID v4
t.boolean() Boolean
t.integer() Integer
t.decimal(precision?, scale?) Precision decimal number
t.text() Long text
t.dateTime() Date and time
t.json() JSON (serialized)
t.enum(values) String enum
Modifier Description
.primary() Marks as primary key
.autoCreate() Auto-generated on creation
.autoUpdate() Updated on each modification
.default(value) Default value
.unique() Unique constraint
.nullable() Allows null
.hidden() Not serialized in responses
fields: {
id: t.uuid().primary().autoCreate(),
name: t.string(100),
email: t.string(255).unique(),
active: t.boolean().default(true),
age: t.integer().nullable(),
price: t.decimal(10, 2).default(0),
bio: t.text(),
createdAt: t.dateTime().autoCreate(),
updatedAt: t.dateTime().autoUpdate(),
metadata: t.json().nullable(),
}

Modifiers can be chained in any order:

t.string(255).unique().nullable()
// ≡ t.string(255).nullable().unique()

Fields with .autoCreate() are excluded from the create input:

// active has default(true), is optional in the input
const { data: user } = await jsorm.users.create({
name: "Juan",
// active: true — optional, automatically assigned as default
});