fix:/prefer the use of column identity over ordinals#4211
fix:/prefer the use of column identity over ordinals#4211johnbrk wants to merge 2 commits intolaunchbadge:mainfrom
Conversation
barry3406
left a comment
There was a problem hiding this comment.
Nice catch — the ordinal-vs-name mismatch in query_as! has bitten a few people.
One thing I noticed: this only switches to column-name lookup for the (true, ColumnType::Exact) branch, but the Wildcard, OptWildcard, and (false, _) arms still use #i (the ordinal). If the column order can differ at runtime (the exact scenario in #4210), those branches would still break. Was that intentional, or should they also use stringify!(#column_ident)?
Also minor: quote::format_ident!("{}", ident) is a no-op when ident is already an Ident — you can pass &ident directly into the quote! interpolation and stringify!(#ident) will work the same way.
|
This was by design because we didn't want to do MxN hashmap lookups when reading a resultset, and it's one of the major reasons we try to discourage However, I think we can get the best of both worlds with a change to how we read rows. Since the shape of the resultset doesn't change while you're reading it, we can resolve column names to ordinals once at the beginning of the resultset and use the ordinals when reading the rows. |
Does your PR solve an issue?
Fixes #4210
Is this a breaking change?
No, just makes
query_as!behave more likequery_as