Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this library for Nullable types in table? #95

Open
gabyx opened this issue Jan 17, 2024 · 2 comments
Open

How to use this library for Nullable types in table? #95

gabyx opened this issue Jan 17, 2024 · 2 comments

Comments

@gabyx
Copy link

gabyx commented Jan 17, 2024

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.

@adwhit
Copy link
Owner

adwhit commented Jan 22, 2024

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

@martsokha
Copy link

I ran into the (probably) same issue when importing Diesel like this:

use diesel::dsl::*;
use diesel::prelude::*;

Replacing use diesel::dsl::*; with more specific imports resolved the Nullable conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants