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
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 😞
The text was updated successfully, but these errors were encountered:
This is unfortunately not possible without some unstable rust features (and a rewrite of how the type-safe macros are implemented). See #514 to track from our side.
Support for
#[sqlx(default)]
was implemented in #495, but it only affects usages of the non-macrosqlx::query_as(...)
.However, this doesn't work for the macros
query_as!
andquery_file_as!
.A test similar to the the following in macros.rs should reproduce the error:
Should/Could this be supported in sqlx, either through
#[sqlx(default)]
or some other mechanism? I had a glance atquote_query_as
,columns_to_rust
andexpand_with_data
, but I couldn't really tell 😞The text was updated successfully, but these errors were encountered: