DocsReference

Field types

Every field builder of locosdk/schema, its options, its TypeScript type, its SQLite column and its MCP input type.

Fields are declared in schema.ts with builders from locosdk/schema. The options are PocketBase's field JSON under PocketBase's own names, minus id, name and type. How a schema fits together: Schema as code.

Types at a glance#

builderTypeScriptSQLite columnMCP input
text()stringTEXT DEFAULT '' NOT NULLstring
email(), url(), editor()stringTEXT DEFAULT '' NOT NULLstring
number()numberNUMERIC DEFAULT 0 NOT NULLnumber, integer when onlyInt, min and max kept
bool()booleanBOOLEAN DEFAULT FALSE NOT NULLboolean
date()stringTEXT DEFAULT '' NOT NULLstring YYYY-MM-DD HH:MM:SS.sssZ
autodate()stringTEXT DEFAULT '' NOT NULLnever an input
select(values)one of values, or '' unless requiredTEXT DEFAULT '' NOT NULLan enum of the values
select(values, { maxSelect: n }), n > 1an array of the valuesJSON DEFAULT '[]' NOT NULLan array of the enum
relation(target)string, a record idTEXT DEFAULT '' NOT NULLa record id of the target
relation(target, { maxSelect: n }), n > 1string[]JSON DEFAULT '[]' NOT NULLan array of ids
file()string, the stored nameTEXT DEFAULT '' NOT NULLnever an input: files go through the UI
file({ maxSelect: n }), n > 1string[]JSON DEFAULT '[]' NOT NULLnever an input
json<T>()T | nullJSON DEFAULT NULLany
password()string, never outputTEXT DEFAULT '' NOT NULLonly password and passwordConfirm on an auth create

The id column is TEXT PRIMARY KEY DEFAULT ('r'||lower(hex(randomblob(7)))) NOT NULL. Columns are sorted by name when a table is made. Dates are UTC text, '' when empty.

Options every field takes#

optionwhat
requireda value must be set. On a select it also drops '' from the type
hiddennever in a response to anyone but a superuser, never in an MCP input, never readable in a client filter
presentablethe field names a record: in relation pickers and in the journal's label
helpa description: the schema form's hint and the MCP tool's field description

Per type#

builderoptions
textmin, max (characters), pattern (a regular expression), autogeneratePattern, primaryKey
email, urlexceptDomains, onlyDomains
editormaxSize, convertURLs
numbermin, max, onlyInt
datemin, max
autodateonCreate, onUpdate (the builder's default is { onCreate: true })
select(values)maxSelect
relation(target)maxSelect, minSelect, cascadeDelete
filemaxSelect, maxSize (bytes, 5 MB when unset), mimeTypes, protected, thumbs
json<T>maxSize
passwordmin, max, pattern, cost (bcrypt, 0 means 10)

geoPoint has no builder. A raw { type: 'geoPoint' } spec works, and the filter reaches geo.lon and geo.lat.

Relations#

  • The target is a collection NAME. defineSchema resolves it to the collection id and throws on an unknown name.
  • cascadeDelete: true: deleting the target removes its id from this field, and deletes this record when the field ends empty.
  • required: true without a cascade: deleting the target is refused when it leaves this field empty.
  • Otherwise the target's id is removed from the field. All of it happens in one transaction.

Indexes#

indexes is a list of raw CREATE INDEX statements, PocketBase's way. A partial unique index works:

indexes: ["CREATE UNIQUE INDEX idx_clients_code ON clients (code) WHERE code != ''"],

A unique index violation answers validation_not_unique on its fields. Dropping an index from a table with rows is refused at boot: a migration does it.

System fields#

base and auth add id, created and updated. auth adds email, emailVisibility, verified, password and tokenKey, and unique indexes on email and tokenKey. Declaring one of these names in fields overrides its options. autodates picks which autodates a collection keeps.

Validation codes#

A refused value answers 400 with data.<field>: { code, message }, PocketBase's codes: validation_required, validation_min_text_constraint, validation_max_text_constraint, validation_invalid_format, validation_not_unique, validation_values_mismatch, validation_invalid_old_password and the others of PocketBase's field validators.

This page as markdown