You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two tables in a one-to-many relation and I am trying to use query_as to retrieve them.
The tables are as follows:
CREATE TABLE IF NOT EXISTS one (
"id" INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
"name" VARCHAR NOT NULL,
)
CREATE TABLE IF NOT EXISTS many (
"id" INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
"name" VARCHAR NOT NULL,
"one" INT,
CONSTRAINT "fk_one"
FOREIGN KEY("one")
REFERENCES one
)
Now, what I want to do is do a left join on these two and receive a One object with a filled many field.
Querying the database is no problem:
let rows = sqlx::query_as!(
One,
r#"
SELECT
one.id,
one.name,
(
many.id,
many.name,
) AS "many!: Vec<Many>"
FROM one
LEFT OUTER JOIN many
ON one.id = many.one
"#
)
.fetch_all(&self.pool())
.await?;
This query runs fine in psql, but... the trait sqlx::Type<sqlx::Postgres> is not implemented for std::vec::Vec<models::Many>
Is there any way to make this work with query_as!? I thought that using the sqlx::Type macro would help here but it doesn't seem to apply for vectors.
Sorry if I missed something, any pointers are much appreciated.
The text was updated successfully, but these errors were encountered:
Using sqlx
0.4.0-beta.1
.I have two tables in a one-to-many relation and I am trying to use query_as to retrieve them.
The tables are as follows:
Then, my models in Rust are these:
Now, what I want to do is do a left join on these two and receive a
One
object with a filledmany
field.Querying the database is no problem:
This query runs fine in
psql
, but...the trait sqlx::Type<sqlx::Postgres> is not implemented for std::vec::Vec<models::Many>
Is there any way to make this work with
query_as!
? I thought that using thesqlx::Type
macro would help here but it doesn't seem to apply for vectors.Sorry if I missed something, any pointers are much appreciated.
The text was updated successfully, but these errors were encountered: