Integer enum in SQLite3 #2776
-
Hi, I am using diesel with SQLite3. What is the best way to support integer enum values in a column? For example, I have defined a column like this in SQL schema:
in
But in actual source code, I would like to define the struct for inserting and querying including this field as: struct Foo {
pub foo_state: FooState,
} where pub enum FooState {
Unknown = 0,
Start = 1,
End = 2,
} The problem is that it is quite difficult to use the enum directly with diesel ORM methods. I had to implement impl<DB> FromSql<Integer, DB> for FooState {
<snip>
}
impl<DB> ToSql<Integer, DB> for FooState {
<snip>
} After that, I can use the enum in Did I miss something obvious & easier way to use integer enum fields? Is it possible to use the enum field in a struct as Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You likely miss one of these derives. Otherwise there is this third party crate, which provides an opinionated way to implement such mappings. |
Beta Was this translation helpful? Give feedback.
You likely miss one of these derives.
Otherwise there is this third party crate, which provides an opinionated way to implement such mappings.