Skip to content

sqlx(default) does not work #3125

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
ItsEthra opened this issue Mar 16, 2024 · 1 comment
Closed

sqlx(default) does not work #3125

ItsEthra opened this issue Mar 16, 2024 · 1 comment
Labels

Comments

@ItsEthra
Copy link

ItsEthra commented Mar 16, 2024

Bug Description

#[sqlx(default)] attribute is supposed to use default value for the type instead of taking it from the query but it doesn't, and causes missing field error.

Minimal Reproduction

#[derive(sqlx::FromRow)]
struct Foo {
    id: i32,

    #[sqlx(default)]
    name: Option<String>,
}

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let pg = sqlx::PgPool::connect("postgres://testing@localhost/testing").await;

    sqlx::query_as!(Foo, "SELECT id FROM Foo");
}

Table foo was created with like that

create table foo(id SERIAL PRIMARY KEY, name TEXT NOT NULL);

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: postgres,runtime-tokio
  • Database server and version: postgres 16.2
  • Operating system: Arch linux
  • rustc --version: rustc 1.78.0-nightly (3cbb93223 2024-03-13)
@ItsEthra ItsEthra added the bug label Mar 16, 2024
@abonander
Copy link
Collaborator

query_as!() does not use FromRow. It says right in the docs: https://docs.rs/sqlx/latest/sqlx/macro.query_as.html

See also #514

@abonander abonander closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants