GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |
GeezerVison is showing github.com — Add a :type annotation to share a row type between queries by egimbernat · Pull Request #4630 · sqlc-dev/sqlc ConversationQueries that select the same columns each get their own row struct ( -- name: GetBook :one :type BookWithAuthor SELECT books.id, books.title, authors.name AS author_name FROM books JOIN authors ON authors.id = books.author_id WHERE books.id = $1; -- name: ListBooksByAuthor :many :type BookWithAuthor SELECT books.id, books.title, authors.name AS author_name FROM books JOIN authors ON authors.id = books.author_id WHERE books.author_id = $1; Both methods return Compatibility is checked strictly, as #3595 asks: generation fails when two queries naming the same type would give different fields (name, Go type or struct tag, in order), and the error names the first differing column: It also fails if the name is already a model's or the query returns a single column, since there is no struct to name. An explicit Changes
Fixes #781
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
A query that returns more than one column gets a struct named after it, so queries selecting the same columns return different types. `:type <TypeName>` after the command names the row type instead, and queries that use the same name return one struct. Generation fails if their columns give different fields, if the name is a model's, or if the query returns a single column. Plugins receive the name as Query.type_name. ParseQueryNameAndType now returns the Metadata, so its callers no longer rebuild it from parts. Fixes sqlc-dev#781 Fixes sqlc-dev#3595 Co-authored-by: ali <[email protected]>
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Allow the specification of shared row datatypes Override query return typeUh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |