-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Nested Type
structs result in "implementation of sqlx::Decode
is not general enough"
#3342
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
The workaround in place is to remove the derive I'm likely implementing the code wrong with lifetimes. Any valid feedback to resolve said issue will be handy for future implementations. |
I figured I'd add the SQL to replicate the desired outcome: SQL to setup test database:CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE board (
id UUID NOT NULL default uuid_generate_v4() PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE panel (
id UUID NOT NULL default uuid_generate_v4() PRIMARY KEY,
board_id UUID NOT NULL,
name text NOT NULL,
CONSTRAINT fk_board
FOREIGN KEY(board_id)
REFERENCES board(id)
ON DELETE CASCADE
);
CREATE TABLE comment (
id UUID NOT NULL default uuid_generate_v4() PRIMARY KEY,
board_id UUID NOT NULL,
panel_id UUID NULL,
body text NOT NULL,
CONSTRAINT fk_board
FOREIGN KEY(board_id)
REFERENCES board(id)
ON DELETE CASCADE,
CONSTRAINT fk_panel
FOREIGN KEY(panel_id)
REFERENCES panel(id)
ON DELETE CASCADE
); SQL to test use case:INSERT INTO board (id, name) VALUES ('8ee4b31f-b678-496e-945c-719319428740', 'Test Board');
INSERT INTO panel (id, board_id, name) VALUES ('e9c28883-4eec-4f15-b3db-1e704b4cd18f', '8ee4b31f-b678-496e-945c-719319428740', 'Test Panel');
INSERT INTO comment (board_id, panel_id, body) VALUES ('8ee4b31f-b678-496e-945c-719319428740', 'e9c28883-4eec-4f15-b3db-1e704b4cd18f', 'Test Comment');
SELECT
board.*,
array_agg(pa) AS "panels"
FROM board
JOIN (
SELECT
panel.*,
array_agg(co) AS "comments"
FROM panel
LEFT OUTER JOIN comment as co
ON panel.id = co.panel_id
GROUP BY panel.id
) pa ON pa.board_id = board.id
WHERE board.id = '8ee4b31f-b678-496e-945c-719319428740'
GROUP BY board.id; The above SQL should return the board with an array of panels with a nested array of comments for the panels. There's some additional logic to be applied (hence the additional board_id column in comments), but the SQL runs successfully with the desired result. I can add test code for Rust as well if necessary. |
I fixed this by cloning the main branch into a vendors directory outside of the project, setting the dependency path to it, then removing the |
Bug Description
I was testing nested
Type
structs for an upcoming project, and ran into a situation "similar" to #1031.Minimal Reproduction
Info
rustc --version
: 1.79.0The text was updated successfully, but these errors were encountered: