Macro sqlx::query_file_as

source ·
macro_rules! query_file_as {
    ($out_struct:path, $path:literal) => { ... };
    ($out_struct:path, $path:literal, $($args:tt)*) => { ... };
}
Available on crate feature macros only.
Expand description

Combines the syntaxes of [query_as!] and [query_file!].

Enforces requirements of both macros; see them for details.

ⓘ
#[derive(Debug)]
struct Account {
    id: i32,
    name: String
}

// let mut conn = <impl sqlx::Executor>;
let account = sqlx::query_file_as!(Account, "tests/test-query-account-by-id.sql", 1i32)
    .fetch_one(&mut conn)
    .await?;

println!("{account:?}");
println!("{}: {}", account.id, account.name);