diesel-sqlite-enum-integer

Crates.iodiesel-sqlite-enum-integer
lib.rsdiesel-sqlite-enum-integer
version0.1.0
created_at2025-06-07 06:22:48.368525+00
updated_at2025-06-07 06:22:48.368525+00
descriptionThis proc macro attribute will allow you to store the enum as integer.
homepagehttps://github.com/Salman-Sali/diesel-sqlite-enum-integer
repository
max_upload_size
id1703746
size5,723
(Salman-Sali)

documentation

README

Note: This proc macro derive will only work if your enum does not contain any variant which accepts values.

Your cargo.toml

[dependencies]
num_enum = "*"
diesel = { version = "*", features = ["sqlite"] }

Your enum

#[diesel_sqlite_enum_integer::enum_to_diesel_integer]
pub enum MyEnum {
    One,
    Two,
    Three
}

The database entity

#[diesel(table_name = crate::schema::my_entity)]
#[derive(Debug, Queryable, Selectable, Identifiable, Associations, PartialEq, Insertable)]
pub struct MyEntity {
    pub id: i32,
    pub my_enum: MyEnum
}

The schema

diesel::table! {
    my_entity (id) {
        id -> Integer,
        my_enum -> Integer
    }
}
Commit count: 0

cargo fmt