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.
Enums§
- Val
- One value inside a rule.
Functions§
- abs
- add
- and
- ceil
- 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
- 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
- rem
- round
- starts_
with - sub
- text
- trim
- upper