pub enum Set<T> {
Unset,
Null,
Value(T),
}Expand description
One field of a generated Setter: unset, NULL, or a value — three states,
distinguished by type.
The three states are the whole point (bob’s omit/null/value): an
unset field does not appear in the INSERT or UPDATE at all — the
column keeps its database default on insert and its current value on update
— while Null writes SQL NULL explicitly. Collapsing the first two
into Option would make “leave it alone” and “erase it” the same call
site, which is precisely the bug this type exists to prevent.
Default is Unset, which is what makes the struct-update
spelling work:
users::table().insert(users::Setter {
name: set("Stephen"),
email: null(),
..Default::default() // every other column: untouched
})Null is representable for every column, NOT NULL ones included — the
constraint violation is the database’s to report, exactly as it is for raw
SQL. Encoding nullability in the Setter’s types was considered and
rejected: it would split Set<T> into two vocabularies and make every
generated field’s type depend on a constraint the schema can change,
for a check the engine performs anyway.
Variants§
Unset
Not mentioned: the field contributes nothing to the statement.
Null
Explicitly NULL, bound as an argument.
Value(T)
A value, bound as an argument.