Skip to main content
SLang models backend data with two complementary constructs:
  • entity defines persisted database records.
  • schema defines reusable structured values that are not stored as their own table.
Use entities for durable resources such as users, orders, documents, memberships, and tasks. Use schemas for request bodies, response shapes, nested values, and structured values that actions pass around.

Entities

An entity becomes a database-backed model. Fields are declared under fields, and relations are declared separately so both sides of a relationship are visible.

Field Types

Persisted fields support these SLang types: Append ? to make a field optional. Use := for static defaults.

Field Metadata

Common field metadata includes:
  • description "..." for generated docs and editor context.
  • minLength 1 for minimum text length.
  • computed <expression> for computed fields.
Defaults must be static values such as strings, numbers, booleans, objects, arrays, or null.

Schemas

Schemas use the same fields shape as entities, but they are structural types, not persisted database tables. Schemas can reference other schemas, including arrays of schemas.

Relations

Relations connect entities and add relation fields to both sides. The general shape is: relation Left[leftField] cardinality --- cardinality Right[rightField] For example, relation User[tasks] 1 --- 0..* Task[owner] means:
  • user.tasks resolves to a list of tasks.
  • task.owner resolves to the owning user.
  • Creating or updating a Task can assign owner := someUser or owner := @subject when the field points to the subject entity.
Use explicit join entities for many-to-many relationships when the relationship carries its own data, such as a membership role.