Engine

4.1. Defining views🔗

Views sit under views, next to entities, and belong to no entity: a view names its source with of. Three views of the shift, in a file of their own:

views:
  shift_overview:
    of: shift
    columns:
      role: (last of ShiftCreated).role
      staffed: count(EmployeeAssigned) - count(EmployeeUnassigned)
      open: (last of ShiftCreated).staff_needed - count(EmployeeAssigned) + count(EmployeeUnassigned)
      cancelled: ever ShiftCancelled
  open_slots_per_role:
    of: shift_overview
    per: role
    where: cancelled = false
    columns:
      shifts: count(shift_overview)
      open_slots: sum(shift_overview.open)
  shift_activity:
    of: shift
    computed: true
    columns:
      assigned_today: count(EmployeeAssigned today)
      last_change: (last of any).at
shiftViewsText · checked against the spec ·

The shift views file loads.

🔗structure
Spec.View : Type
Spec.View : Type

A view: one row per key of an entity (of: entity), or rows built from another view's rows (of: view, grouped by per). Columns are rule expressions. Kept views are updated on every append; computed: true views have no write path and are evaluated when read.

Spec.View.mk
name : String

its name, under views

source : String

of: an entity or a view

per : List String

per: columns of the source view to group by

filter : Option CondExpr

where: which keys or source rows it has

columns : List (String × Column)

columns, in order

computed : Bool

computed: true

  • A view of an entity has one row per key with events; with where, only the keys whose history meets the condition. Its columns are rule expressions over the key's history, as in an invariant (View.ofEntity).

  • A view of a view reads the source view's rows. Each source row is an event whose type is the source view's name and whose fields are the row's columns, so count(shift_overview) and sum(shift_overview.open) are ordinary rule expressions. With per, one row per group of the source rows by those columns; where keeps the source rows that meet it (View.ofView).

  • A column is a value or a condition; a condition's value is a boolean.

After shift s1 for one cook is created and Anna assigned, and shift s2 for two cooks is created and cancelled: