Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.withsutro.com/llms.txt

Use this file to discover all available pages before exploring further.

Actions are the functions of your backend. They accept typed parameters, execute logic, modify the database, and return data.

Defining an action

Actions have a signature defining inputs and the return type.
action CreatePatient(data: Patient): Patient
  description "Create a new patient in a specific clinic."
  body
    clinic := single Clinic where @id == data.clinicId
    
    return create Patient {
      Clinic := clinic
      fullName := data.fullName
    }

Data access

SLang provides high-level keywords for querying data.

Fetching a single record (single)

Use single when you expect exactly one result (e.g., looking up by ID). It throws an error (404 in HTTP context) if the record is not found.
patient := single Patient where @id == patientId

Fetching lists (pageOf)

Use pageOf to retrieve a Page<Model> value matching a condition. A page is an object with items, total, and offset; use page.items when you need the underlying array.
activePatients := pageOf Patient where 
  Clinic.id == clinicId and 
  Status == "active"

Modifying data

Creating records

newItem := create Item {
  Name := "New Item"
  Owner := @subject
}

Updating records

update newItem {
  Status := "processed"
}

Control flow

Loops

Iterate over the items array on a page returned by pageOf.
page := pageOf Item where status == "pending"
for item in page.items
  update item { status := "processed" }