Skip to content

Rename attribute macro fails with query_as! #1372

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

Closed
zohaad opened this issue Aug 12, 2021 · 1 comment
Closed

Rename attribute macro fails with query_as! #1372

zohaad opened this issue Aug 12, 2021 · 1 comment

Comments

@zohaad
Copy link

zohaad commented Aug 12, 2021

The following piece of code:

let user = sqlx::query_as!(User, "select * from users where email = $1", self.email)
    .fetch_one(pool)
    .await
    .ok()?;

Produces this error:

error[E0560]: struct `User` has no field named `user_id`
  --> src/lib.rs:36:20
   |
36 |         let user = sqlx::query_as!(User, "select * from users where email = $1", self.email)
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `User` does not have this field
   |
   = note: available fields are: `id`, `email`, `password`
   = note: this error originates in the macro `$crate::sqlx_macros::expand_query` (in Nightly builds, run with -Z macro-backtrace for more info)

While the struct has the appropriate rename macro:

#[derive(sqlx::FromRow)]
struct User {
    #[sqlx(rename = "user_id")]
    id: Uuid,
    email: String,
    password: String,
}

I am using the correct uuid type: use sqlx::{types::Uuid, PgPool};

@abonander
Copy link
Collaborator

The query_as! macro does not currently use the FromRow derive: #514

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

2 participants