Expand description
The values a compiled row rule computes with, and its operators.
The schema generator compiles each row rule a module declares (a condition
over one row’s own fields) into a Rust expression over Val, built from
the functions here, and evaluates it against the row the write would store,
read through the row’s JSON form so enums, decimals and dates arrive as the
text and numbers their columns hold.
The semantics are SQL’s, because the same rule also compiles to a CHECK
constraint and both must give one answer:
- A missing or null field is
Val::Null, and an operator over a null is null:name.length >= 1with no name is neither true nor false. &&,||and!are three-valued:false && nullis false,true || nullis true, anything else with a null is null.- A rule
holdsunless it is definitely false, as aCHECKpasses on null.x == nullandx != nulltest for null itself and are never null. - A comparison between a number and a text parses the text, the way a
decimal column serialized as
"12.50"compares to0; a comparison between a time and a text parses the text as a timestamp or a date.
A rule may also read the row before the write ($old.x, through field
on that row), the writer (actor) and the time of the write (at).
Enums§
- Val
- One value inside a rule.
Functions§
- abs
- actor
- The writer, as
$actor.idreads it; null for a job, a seed or an unscoped caller. - add
- and
- at
- The time of the write, as
now()reads it. - ceil
- changed
- Whether any of
fieldsdiffers between the row before and the row after a write. A rule about the time of the write checks an update only when it changes what the rule reads, so a later edit of a row whose deadline has passed is not a break. - coalesce
- The first value that is not null.
- cond
c ? t : e, as SQL’sCASE WHEN c THEN t ELSE e END: a null condition takese.- contains
a.contains(b): a text containing a text, or a list containing an item.- div
- Division by zero is null rather than an error: a rule never panics a write.
- ends_
with - eq
- field
- The row’s field
name;Val::Nullwhen it is absent or null. - floor
- ge
- gt
- has_
role $actor.has_role(role): null without a writer, without an installed roles source (crate::actor_roles), or when the source cannot tell; the rule then holds.- holds
- Whether a rule’s value lets the write through: everything but a definite
false. - in_list
a in [..], as SQL’sIN: true on a match, null whenais null or no item matched but one was null, false otherwise.- is_
empty - is_
not_ null - is_null
- le
- length
- A text’s length in characters (code points, as on every target), or a list’s.
- lower
- lt
- matches
a matches 'pattern': whether the text contains a match of the pattern. The generator only emits patterns that compile.- mul
- ne
- neg
- not
- not_in
- or
- referencing
- How many rows still reference the row being deleted:
sqlcounts them with the row’s id as$1, run on the request’s own connection. Null outside a request or without an id. - rem
- round
- starts_
with - sub
- text
- trim
- upper