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

Implement accessing a column by name for the Any driver to fix FromRow #464

Closed
sciyoshi opened this issue Jun 30, 2020 · 0 comments
Closed

Comments

@sciyoshi
Copy link

With the following minimal test case:

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.

@mehcode mehcode closed this as completed in 0b2844b Jul 3, 2020
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

1 participant