Field types
Use t.* to define field types. Each type returns a FieldChain with chainable modifiers.
Available types
Section titled “Available types”| 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 |
Modifiers
Section titled “Modifiers”| 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 |
Examples
Section titled “Examples”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(),}Chaining
Section titled “Chaining”Modifiers can be chained in any order:
t.string(255).unique().nullable()// ≡ t.string(255).nullable().unique()Default values
Section titled “Default values”Fields with .autoCreate() are excluded from the create input:
// active has default(true), is optional in the inputconst { data: user } = await jsorm.users.create({ name: "Juan", // active: true — optional, automatically assigned as default});