-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
duplicateThis issue or pull request already existsThis issue or pull request already exists
Description
Support for #[sqlx(default)] was implemented in #495, but it only affects usages of the non-macro sqlx::query_as(...).
However, this doesn't work for the macros query_as! and query_file_as!.
A test similar to the the following in macros.rs should reproduce the error:
#[derive(FromRow)]
struct Foo {
id: i32,
#[sqlx(default)]
name: Option<String>,
}
#[sqlx_macros::test]
async fn test_query_as_default() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().await?;
let foo = sqlx::query_as!(Foo, "SELECT id \"id!\" from (VALUES (1)) foos(id)",)
.fetch_one(&mut conn)
.await?;
println!("{:?}", foo);
Ok(())
}
error[E0063]: missing field `name` in initializer of `Foo`
Should/Could this be supported in sqlx, either through #[sqlx(default)] or some other mechanism? I had a glance at quote_query_as, columns_to_rust and expand_with_data, but I couldn't really tell 😞
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already exists