How can I validate a session id with diesel.rs?

I have this:

pub fn is_token_valid(conn: &mut SqliteConnection, id: String) -> bool {
    use crate::diesel::schema::users::dsl::session_id;
    use crate::diesel::schema::users::dsl::users;
    use diesel::OptionalExtension;

    let user_with_session_id = users.filter(session_id.eq(id)).first::<User>(conn);

    todo!()
}

I want to search the database to see if a user has this session id, and if it finds it, return true, otherwise return false.
but it just gives me awful error messages:

error[E0277]: the trait bound `(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Timestamp, diesel::sql_types::Nullable<diesel::sql_types::Text>): load_dsl::private::CompatibleType<User, Sqlite>` is not satisfied
     |
58   |     let user_with_session_id = users.filter(session_id.eq(id)).first::<User>(conn);
     |                                                                -----         ^^^^ the trait `load_dsl::private::CompatibleType<User, Sqlite>` is not implemented for `(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Timestamp, diesel::sql_types::Nullable<diesel::sql_types::Text>)`
     |                                                                |
     |                                                                required by a bound introduced by this call
     |
     = help: the following other types implement trait `load_dsl::private::CompatibleType<U, DB>`:
               (ST0, ST1)
               (ST0, ST1, ST2)
               (ST0, ST1, ST2, ST3)
               (ST0, ST1, ST2, ST3, ST4)
               (ST0, ST1, ST2, ST3, ST4, ST5)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8)
             and 24 others

I also have tried using .limit(1) but had no luck either

Are you sure the User type you placed in the turbofish is the Diesel model?

The docs have a section on reading error messages from diesel, it looks like the first bullet point matches your error

What are the definitions of User and users in the schema? An issue like this is hard to debug without all the information.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.