-
Notifications
You must be signed in to change notification settings - Fork 883
Improve support for SQL functions that return tables #1973
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
base: main
Are you sure you want to change the base?
Conversation
4e58b26
to
1b847a3
Compare
@kyleconroy Is this change out of scope for this project? If so, I can go ahead and close this to clear up the queue. If not, I'll try to find some time to rebase and resolve conflicts. |
I don't think it's out of scope necessarily. When @kyleconroy and I last discussed I think we had settled on support for queries using the I haven't had a chance to look closely through your PR to determine whether it meets that requirement though. |
Great. Yes, that's exactly what it's supposed to do. You can see a couple of examples here. |
8563994
to
88ab842
Compare
The 2 force-pushes are for
|
A few pieces of feedback on these changes. Instead of generating structs inside This change simplifies the code as well, as we no longer need to pass function information to the codegen plugin. const booksByTagsViaFunc = `-- name: BooksByTagsViaFunc :many
SELECT book_id, title, name, isbn, tags FROM sqlc_book_schema.books_by_tags_func($1::VARCHAR[])
`
type BooksByTagsViaFuncRow struct {
BookID sql.NullInt32
Title sql.NullString
Name sql.NullString
Isbn sql.NullString
Tags sql.NullString
}
func (q *Queries) BooksByTagsViaFunc(ctx context.Context, dollar_1 []string) ([]BooksByTagsViaFuncRow, error) {
...
} As for the tests you've added, can you move all the changes for the examples directory to individual testcases into the end-to-end directory? The examples lean towards simplicity and most users of sqlc don't use stored procedures. |
88ab842
to
9d1a68d
Compare
Indeed, that turned out to be a much better approach.
Sure, I've added an |
@kyleconroy This is ready for another look. |
9d1a68d
to
34df824
Compare
34df824
to
66f537c
Compare
I rebased this on |
This change adds an
IsArray
field for function parameters and creates structs for PosgreSQL functions that return tables.There are a couple of examples in
internal/endtoend/testdata/func_return_table/
, in addition to the existing examples infunc_return
that didn't regress.closes #1322