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.
enum TaskStatus
  values
    todo
    in_progress
    done

entity User
  description "Authenticated application user."
  subject
  identity email
  fields
    email: EMAIL
      description "Login email address."
    displayName: TEXT?

entity Task
  description "A task owned by a user."
  fields
    title: TEXT
      minLength 1
    status: TaskStatus := "todo"
    dueDate: DATE?

relation User[tasks] 1 --- 0..* Task[owner]
  description "Each task belongs to one user."

Field Types

Persisted fields support these SLang types:
TypeUse
TEXTGeneral strings.
EMAILEmail-shaped strings; commonly used as identity fields.
PHONE_NUMBERPhone numbers.
ADDRESSPostal address text.
NUMBERInteger or decimal numbers.
CURRENCY_AMOUNTCurrency amount strings.
BOOLEANtrue or false.
DATECalendar dates.
TIMETime values.
DATE_TIMETimestamps.
URLWeb links.
FILEUploaded or stored document/blob values.
ENUM("a", "b")Inline string enum.
SomeEnumNamed enum declared with enum.
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.
schema Address
  description "A mailing address."
  fields
    street: TEXT
    city: TEXT
    postalCode: TEXT

schema LineItem
  fields
    productName: TEXT
    quantity: NUMBER
    unitPrice: CURRENCY_AMOUNT

schema OrderSummary
  fields
    orderNumber: TEXT
    shipping: Address
    items: [LineItem]
    totalAmount: CURRENCY_AMOUNT

action BuildOrderSummary(orderNumber: TEXT, city: TEXT): OrderSummary
  body
    return {
      orderNumber := orderNumber
      shipping := {
        street := "1 Main St"
        city := city
        postalCode := "94105"
      }
      items := []
      totalAmount := 0
    }

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.