sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Error with compiled query_as macro

Open tamayotchi opened this issue 2 years ago • 0 comments

Bug Description

I am encountering an error when using the compiled version of query_as. However, this error does not occur when I use the non-compiled version.

Minimal Reproduction

#[derive(Debug, FromRow)]
struct Account {
     id: i32,
     data: Option<sqlx::types::Json<Data>>
 }

#[derive(Debug, serde::Deserialize)]
struct Data {
    data: i32,
}

Using simple query_as:

let account = sqlx::query_as::<_, Account>(
   r#"SELECT id, data FROM (SELECT 1 as id, '{"data": 1}' as data) AS accounts;"#
).fetch_one(pool).await?;
println!("ACCOUNT {:?}", account); // ACCOUNT Account { id: 1, data: Some(Json(Data { data: 1 })) }

Using the Compile-time verification:

let account = sqlx::query_as!(
   Account,
   r#"SELECT id, data FROM (SELECT 1 as id, '{"data": 1}' as data) AS accounts;"#
);

image

Info

  • SQLx version: 0.7
  • SQLx features enabled: ["mysql", "runtime-tokio", "tls-rustls", "chrono"]
  • Database server and version: MySQL 8.0.34-Vitess
  • Operating system: Ubuntu
  • rustc --version: 1.74.1

tamayotchi avatar Jan 13 '24 10:01 tamayotchi