admin管理员组

文章数量:1122846

let user_result = users
 .filter(username.eq(&login_data.username))
 .select((id, username, password_hash, created_at)) 
 .first::<User>(&mut conn);

I take this error ;

the trait bound (Integer, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Timestamp>): load_dsl::private::CompatibleType<User, _> is not satisfied this is a mismatch between what your query returns and what your type expects the query to return the fields in your struct need to match the fields returned by your query in count, order and type consider using #[derive(Selectable)] or #[derive(QueryableByName)] + #[diesel(check_for_backend(_))] on your struct User and in your query .select(User::as_select()) to get a better error message the following other types implement trait load_dsl::private::CompatibleType<U, DB>

this is my user struct :

#[derive( Selectable, Serialize, Deserialize, Debug)]
pub struct User {
  pub id: i32,
  pub username: String,
  pub password_hash: String,
  pub created_at: Option<NaiveDateTime>, // Nullable field
}

and also schema.rs :

diesel::table! {
users (id) {
    id -> Int4,
    username -> Varchar,
    password_hash -> Varchar,
    created_at -> Nullable<Timestamp>,
 }
}

how can i fix that

本文标签: RustThe Trait Bound dieselexpressionselectbySelectByltUserPggtStack Overflow