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
Document sqlc behavior for queries with JOINs #643
Comments
Were the docs added? I'm wondering the same thing |
@kyleconroy I'd love to work on this. Before I do, I'd love your thoughts on doing the following: -- schema.sql
CREATE TABLE users (id text);
CREATE TABLE usernames (user_id text, name text);
-- query.sql
-- name: GetUsersWithNames :many
SELECT users.*, usernames.name FROM users JOIN usernames ON users.id = usernames.user_id; Currently, this would generate a struct like: type GetUsersWithNamesRow struct {
ID string
Name string
} I'm wondering if we could embed existing structs instead... like: type GetUsersWithNamesRow struct {
User
Name string
} This would enable complex cross-table queries sharing structs. |
@kylecarbs Please see #363 for a discussion about embedding structs. It's a bit more complicated that it seems. |
This is doubly important now that #983 has been merged. |
Bump - and progress here? |
Bump again - any updated? |
now that we have sqlc.embed merged, why is it not documented in the docs? I'd love to help out if needed, but we need to add documentation for it |
bump? |
It's not in the main documentation, but there's a quick summary of the new |
Sorry for the lack of documentation. We added a dedicated section for this in the last release. |
I'm trying to create a query with LEFT JOIN, but a query parameter with 13 entries is generated, but my query only has 11 entries. My query:
Generated parameter:
My classes:
It appears that |
Hi. Thanks for a great project. The idea is really promising and fresh for the Go ecosystem!
One thing wasn't clear for me from the existing documentation and examples:
How sqlc handles relations and complex queries with JOINs, does it still uses flat structures for the output or it somehow reuses and embeds structs that represent a single table.
After going through existing issues I found out that sqlc goes with the simplest approach and generates a flat structure for every query even a complex one with a JOIN.
I think you should explicitly document it or add an example with a JOIN, because maybe not only me was looking for something like that.
The text was updated successfully, but these errors were encountered: