Skip to main content
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(clinicId: TEXT, fullName: TEXT): Patient
  description "Create a new patient in a specific clinic."
  body
    clinic := single Clinic where id == clinicId
    
    return create Patient {
      Clinic := clinic
      `Full Name` := 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 paginated lists of data matching a condition.
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 collections returned by pageOf.
items := pageOf Item where status == "pending"
for item in items
  update item { status := "processed" }