How to work with nested struct #1446
-
Greetings and thanks for your project! Could you tell me how can I make this structure for query response? struct Image {
url: String,
width: i64,
heigth: i64
}
struct Profile {
id: i64,
image: Option<Image>
}
struct User {
id: i64,
profile: Profile
} I try this query, but this is not the correct syntax for postgres: let user = sqlx::query_as!(User, r#"
SELECT u.id (p.id, (i.url, i.width, i.heigth) as "image!: Image") as "profile!: Profile"
FROM users u
JOIN profile p ON u.id = p.user_id
JOIN image i ON p.image_id = i.id
WHERE u.id = $1"#, 1).fetch_one(&pool).await.unwrap(); I can convert |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Wish there was an answer to this - been trying to figure it out for months. SQLx doesn't support flattening right now so I don't think it's possible with SQLx at the moment :( |
Beta Was this translation helpful? Give feedback.
-
@ikrivosheev did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
Hey @ikrivosheev , I know this is an old issue but do you know if this is possible now using |
Beta Was this translation helpful? Give feedback.
-
However, it should work with the query_as() function, which sets a |
Beta Was this translation helpful? Give feedback.
Wish there was an answer to this - been trying to figure it out for months. SQLx doesn't support flattening right now so I don't think it's possible with SQLx at the moment :(