Enums
An enum is a named, closed set of variants declared as schema. Columns typed by an enum can only hold one of its variants - the database enforces what would otherwise be a stringly-typed convention in application code.
Declaring and using an enum
Declare the variants once, then use the enum as a column type. Values are written as variant paths - dm_enum::status::Active - so a typo is a schema error, not silent bad data. Under the hood each variant is stored as a compact tag (its index), which is what a plain read shows. Run the snippets on this page in order:
Variants with payloads
Variants can carry typed fields, making an enum a full sum type. A column holding Circle { radius } or Rectangle { width, height } stores exactly one variant's payload; reads flatten the variant tag and every possible field, with none for fields of the variants not present:
Enum, dictionary, or plain string?
- --Fixed set known at design time, enforced by the schema: enum.
- --Open set discovered at runtime, stored compactly: a dictionary.
- --Free-form text: a plain
utf8column.
