- Notifications
You must be signed in to change notification settings - Fork976
Generating named queries and interfaces#711
-
With large project there will be huge amount of functions. It will be much better if we support named queries and interfaces. For example Will generate: With this named Queries and interfaces support, I don't need to split queries into different packages like#710 |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 4 comments
-
Can you explain why the different package approach doesn't work for you? I'd rather not more complexity to query names, especially features that may not map directly to other programming languages. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
The main reason is that each generated package will contain a models.go,which will duplicate the same structure across different packages. forexample, if there are 3 tables: authors, books and orders, it may end up 9typesAuthor type: authors.Author, books.Author, orders.AuthorBook type: author.Book, books.Book, orders.BookOrder type: authors.Order, books.Order, orders.Order |
BetaWas this translation helpful?Give feedback.
All reactions
-
Another reason is the current approach will easily generate one big interface with too many methods in it, which will be a pain to mock. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
A slightly different tack would be to have separate files with queries, where each file would result in a separate interface. The mapping could either be defined in the SQL source code with a meta-data comment "at file level" or as a mapping in the sqlc.yaml. The generic interface name |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #711 on September 12, 2020 23:29.