-
Notifications
You must be signed in to change notification settings - Fork 1.4k
JOIN and query_as! #657
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
Comments
@alucryd can you give an example of what you're trying to do? |
Sure thing, this is the select I'm talking about: https://github.com/alucryd/oxyromon/blob/a3b7b1ff10473a7ac9c689166dafb502616435b8/src/database.rs#L593 Had to narrow the select to return only the roms columns, or else query_as! would complain because there were more columns than fields in the struct. Also scratched my head for a while when using the non macro version because the returned Rom struct contained fields from the joined games table which wasn't obvious at first. So how do you tell sqlx that the returned rows contain 2 structs? diesel uses a tuple in this case but I could't find the sqlx equivalent. |
I'm in the process of trying to figure this out as well, based on the examples in #1014 I think the following is supposed to work: struct CombinedStruct {
a_result: A,
b_result: B,
}
query_as!(CombinedStruct,
r#"SELECT a as "a_result!: A", b as "b_result!: B"
FROM first_table as a INNER JOIN second_table as b ON a.some_col = b.other_col"#
).fetch_all(conn).await?; This assumes the A and B structs are derived with sqlx::Type. You can also change |
I get
which seems to just be the same Option decode problem. My struct also gets flagged with a warning "unnecessary braces around function argument", if I add the sqlx::Type derive, but unsure if that's a problem |
Yeah, that's also kind of a bug in the macros. Maybe adding |
How do you handle joined rows with the query_as! syntax? I tried specifying a tuple but it doesn't work and I didn't find any example anywhere.
The text was updated successfully, but these errors were encountered: