Open lcnlvrz opened 9 months ago
By the moment the workaround that works for me is to create views and then use sqlc.embed
schema.sql
CREATE VIEW drivers AS (
SELECT * FROM persons WHERE type = 'driver'
);
CREATE VIEW recipients AS (
SELECT * FROM persons WHERE type = 'recipient'
);
query.sql
SELECT sqlc.embed(track), sqlc.embed(driver), sqlc.embed(recipient)
FROM tracks track
JOIN drivers driver ON track.driver_id = driver.id
JOIN recipients recipient ON track.recipient_id = recipient.id
WHERE track.id = $1 LIMIT 1;
The workaround is great, however it also leads to new types in the response struct, which makes it less useful in some cases.
e.g. the example would create something like this:
type GetTrackRow {
Track Track
Driver Driver
Recipient Recipient
}
Version
1.25.0
What happened?
I just need to perform a query that joins multiple rows from same table and i expect sqlc to take alias from query when build final go structs
In current version when you join multiple times from same table, the final struct looks something like:
Relevant log output
No response
Database schema
SQL queries
Configuration
Playground URL
No response
What operating system are you using?
Linux
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go