diesel-derive-enum icon indicating copy to clipboard operation
diesel-derive-enum copied to clipboard

How to use this library for Nullable types in table?

Open gabyx opened this issue 1 year ago • 1 comments

I have the following table:

pub mod sql_types {
    #[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]
    #[diesel(postgres_type(name = "result_t"))]
    pub struct ResultT;
}

diesel::table! {
    use diesel::sql_types::*;
    use super::sql_types::ResultT;

    jobs (id) {
        id -> Varchar,
        name -> Varchar,
        blob_digest -> Varchar,
        converter_result -> Nullable<ResultT>,
        converter_log -> Nullable<Text>,
    }
}

and I use the following:

#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, diesel_derive_enum::DbEnum)]
#[ExistingTypePath = "crate::schema::sql_types::ResultT"]
pub enum ConverterResult {
    Idle,
    Queued,
    Running,
    Done,
}

But this does not work because of the Nullable, I looked at the tests, but did not find out how it works for Nullables.... How can I use this. It would help to directly put that into the demo in the README.md maybe.

Thanks.

gabyx avatar Jan 17 '24 21:01 gabyx

What query are you using and what error are you getting? It certainly should work. The tests for nullables are here: https://github.com/adwhit/diesel-derive-enum/blob/master/tests/src/nullable.rs

adwhit avatar Jan 22 '24 10:01 adwhit