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
版权声明:本文标题:Rust - The Trait Bound `diesel::expression::select_by::SelectBy<User, Pg> - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300416a1930806.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论