Skip to main content

Module default_literal

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: true or false, in any case.
  • Int, BigInt: a decimal integer inside i64.
  • 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). A Cuid must be cuid-shaped, a Uuid a UUID, and a DateTime an RFC 3339 timestamp.
  • an enum: one of its variants, bare or quoted.

Every other field type takes no literal default.

Structs§

LiteralDefault
A literal default: its value, and the SQL literal a migration writes.

Enums§

LiteralValue
The value a literal default stands for.

Functions§

literal_default
Interpret inner, the text of @default(inner), as a literal for a field of type ty. enum_decl is 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; None when inner is not one quoted string.