You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use sqlx::any::AnyConnection;
#[derive(sqlx::FromRow, Debug)]
pub struct User {
pub id: i64,
pub username: String,
}
impl User {
pub async fn get_from_id(db: &mut AnyConnection, id: i64) -> Option<Self> {
sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = ? LIMIT 1")
.bind(id)
.fetch_one(db)
.await
.ok()
}
}
I get the following compile error:
error[E0277]: the trait bound `str: sqlx_core::row::ColumnIndex<sqlx_core::any::row::AnyRow>` is not satisfied
--> src/model.rs:34:14
|
34 | .fetch_one(db)
| ^^^^^^^^^ the trait `sqlx_core::row::ColumnIndex<sqlx_core::any::row::AnyRow>` is not implemented for `str`
According to @mehcode on Discord, the Any driver needs to implement accessing a column by name for FromRow to work.
The text was updated successfully, but these errors were encountered:
With the following minimal test case:
I get the following compile error:
According to @mehcode on Discord, the
Any
driver needs to implement accessing a column by name forFromRow
to work.The text was updated successfully, but these errors were encountered: