Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions sqlx-macros-core/src/query/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,27 @@ pub fn quote_query_as<DB: DatabaseExt>(
|(
i,
RustColumn {
var_name, type_, ..
var_name,
type_,
ident,
},
)| {
match (input.checked, type_) {
// we guarantee the type is valid so we can skip the runtime check
(true, ColumnType::Exact(type_)) => quote! {
// binding to a `let` avoids confusing errors about
// "try expression alternatives have incompatible types"
// it doesn't seem to hurt inference in the other branches
#[allow(non_snake_case)]
let #var_name = row.try_get_unchecked::<#type_, _>(#i)?.into();
},
(true, ColumnType::Exact(type_)) => {
let column_ident = quote::format_ident!("{}", ident);

quote! {
// binding to a `let` avoids confusing errors about
// "try expression alternatives have incompatible types"
// it doesn't seem to hurt inference in the other branches
#[allow(non_snake_case)]
let #var_name = row.try_get_unchecked::<#type_, _>(
// use the column identity as the index,
stringify!(#column_ident)
)?.into();
}
}
// type was overridden to be a wildcard so we fallback to the runtime check
(true, ColumnType::Wildcard) => quote! (
#[allow(non_snake_case)]
Expand Down
Loading