Macro sql_enum

Source
macro_rules! sql_enum {
    (
        feature_gated:
        $(#[$enum_meta:meta])* $enum_ident:ident,
        $sql_type_lit:literal,
        $(#[$type_meta:meta])* $type_ident:ident,
        {$($variant_ident:ident = $variant_lit:literal),* $(,)?}
    ) => { ... };
    (
        $(#[$enum_meta:meta])* $enum_ident:ident,
        $sql_type_lit:literal,
        $(#[$type_meta:meta])* $type_ident:ident,
        {$($variant_ident:ident = $variant_lit:literal),* $(,)?}
    ) => { ... };
    (
        @impl__
        $do_feature_gate:ident
        $(#[$enum_meta:meta])* $enum_ident:ident,
        $sql_type_lit:literal,
        $(#[$type_meta:meta])* $type_ident:ident,
        {$($variant_ident:ident = $variant_lit:literal),* $(,)?}
    ) => { ... };
}
Expand description

Defines a new SQL enum

The first argument is the resulting type for use in rust code. The second argument is the serialized version of the enum name. The third argument is the sql type. The 4th argument is the string identifier of the sql type.

After that follow the variants of the enum with the syntax of: RustVariant = byte-string

§Example

sql_enum!(
    CustomSqlEnum,          // Name of the Rust enum name
    "custom_sql_enum",      // Name of the type name in sql
    CustomSqlEnumType,      // Name of the diesel enum type repr
    {
        Variant1 = b"variant1", // the variants with their respective sql string representation
        Variant2 = b"variant2",
    }
);