FrontierJS

Litestone guide / Schema

Choosing a field

Two questions pick the attribute for a value: is there a column, and who computes it, and when?

The answers decide whether a caller can write it and whether a query can name it.

model Line {
  id        Int      
  title     String                         // the caller supplies it
  qty       Int      (1)           // the caller may, SQLite fills it otherwise
  number    String               // the caller, once, at create
  amount    Int      (qty * 2)   // SQLite, from this row
  late      Boolean  (qty > 5)     // SQLite, in the SELECT
  coupon    String?              // input only, nothing stores it
}
const l = await db.line.create({ data: { title: 'Rope', number: 'L-1', qty: 4 } })
const flagged = await db.line.findMany({ where: { late: false }, orderBy: { amount: 'desc' } })
if (l.amount !== 8 || flagged.length !== 1) throw new Error('unexpected row')

What else it can do

AttributeColumnCaller writesFilter and sortComputed by
plain fieldyesyesyesthe caller
@default(...)yesyesyesSQLite, on insert
@systemyesno, the app names ityesthe application
@immutableyesat create onlyyesthe caller, once
@guardedyesasSystem() onlyasSystem() onlythe application
@generatedyesnoyesSQLite, per read or write
@derivednonoyesSQLite, in the SELECT
@from(Model, ...)nonoyes, but no groupBySQLite, a subquery
@computednononoJavaScript, after the read
@transientnoyes, nothing stores itnonobody

Every no in the write column is a refusal that names the attribute.

@system and @guarded are access rules, so a schema holding either refuses every model with no @@gate, @@allow or @@deny below asSystem(), the model carrying the column included. @@gate(0) on a model declares it public.

In depth: Modeling § Which feature makes this field?