Module default_literal
Expand description
What a literal @default(...) means for its field (cratestack#1234).
A literal default reaches two places. The migration writes it into the
column’s DEFAULT clause, and the embedded runtime, whose tables are
not built from migrations, binds it on create. Both need the same
answer to “what value is this”, so both go through literal_default,
which also lets cratestack check refuse a literal that does not fit
its field instead of letting it fail when the migration is applied.
The accepted spellings, by field type:
Boolean:trueorfalse, in any case.Int,BigInt: a decimal integer insidei64.Float: a finite decimal number, optionally with an exponent.Decimal: a plain decimal number (-12.50), bare or quoted.String,Cuid,Uuid,DateTime: a quoted string,"…"or'…', where a backslash escapes the next character (the attribute scanner’s rule,super::attribute_text). ACuidmust be cuid-shaped, aUuida UUID, and aDateTimean RFC 3339 timestamp.- an enum: one of its variants, bare or quoted.
Every other field type takes no literal default.
Structs§
- Literal
Default - A literal default: its value, and the SQL literal a migration writes.
Enums§
- Literal
Value - The value a literal default stands for.
Functions§
- literal_
default - Interpret
inner, the text of@default(inner), as a literal for a field of typety.enum_declis the field’s enum, when it has one. The error says why the literal does not fit. - sql_
string - A single-quoted SQL string literal.
- unquote
- The content of a
"…"or'…'literal, unescaped;Nonewheninneris not one quoted string.