Title: Proposal: Add option to emit `//go:generate` annotation · Issue #3124 · sqlc-dev/sqlc · GitHub
Open Graph Title: Proposal: Add option to emit `//go:generate` annotation · Issue #3124 · sqlc-dev/sqlc
X Title: Proposal: Add option to emit `//go:generate` annotation · Issue #3124 · sqlc-dev/sqlc
Description: What do you want to change? I would like sqlc to provide an option to emitting //go:generate annotation on generated models file in order to let us auto-generate the extended codes using go generate command. Proposal I would like to add ...
Open Graph Description: What do you want to change? I would like sqlc to provide an option to emitting //go:generate annotation on generated models file in order to let us auto-generate the extended codes using go generat...
X Description: What do you want to change? I would like sqlc to provide an option to emitting //go:generate annotation on generated models file in order to let us auto-generate the extended codes using go generat...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/3124
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: Add option to emit `//go:generate` annotation","articleBody":"### What do you want to change?\r\n\r\nI would like `sqlc` to provide an option to emitting `//go:generate` annotation on generated models file in order to let us auto-generate the extended codes using `go generate` command.\r\n\r\n#### Proposal\r\n\r\nI would like to add some option like `go_generate_annotations` in config that lead `sqlc` to emit `go:generate` annotation.\r\n\r\n```yaml\r\nsql:\r\n - gen:\r\n go:\r\n go_generate_annotations:\r\n - generator: go-genaccessor\r\n emit_into_models_file: true\r\n```\r\n\r\nExpected result in `models.go`:\r\n\r\n```go\r\n//go:generate go-genaccessor\r\n```\r\n\r\n#### Background\r\n\r\nI was firstly looking for the way to add getter/setter methods to the `sqlc`-generated models, and found that there is no straightforward option to achieve, nor any plan in future to support it. Instead, there have been some comments to the following issues that encouraging the use of any another tool to extend the code.\r\n\r\n- https://github.com/sqlc-dev/sqlc/pull/2471\r\n- https://github.com/sqlc-dev/sqlc/pull/387\r\n\r\nGolang already provides an official `go generate` subcommand (https://go.dev/blog/generate) that let us autogenerate the code, but that command requires `//go:generate` annotation on the subjected file in order to tell the command which file should be subjected and which plugin should be used for autogeneration.\r\n\r\n#### Goal\r\n\r\nI confirmed that I was able to add extra struct tags to the columns of the model struct can be achieved with following config:\r\n\r\n```yaml\r\nsql:\r\n - gen:\r\n go:\r\n overrides:\r\n - column: items.id\r\n go_struct_tag: 'getter:\"GetID\" setter:\"SetID\"'\r\n```\r\n\r\nWhich results to the following code, which seems perfect.\r\n\r\n```go\r\ntype Item struct {\r\n\tID uuid.UUID `getter:\"GetID\" setter:\"SetID\"`\r\n}\r\n```\r\n\r\nHowever that file doesn't obviously provide the `go:generate` annotation and I couldn't achieve the generation of getters and setters\"\r\n\r\n### What database engines need to be changed?\r\n\r\n_No response_\r\n\r\n### What programming language backends need to be changed?\r\n\r\nGo","author":{"url":"https://github.com/ktogo","@type":"Person","name":"ktogo"},"datePublished":"2024-01-10T17:19:27Z","url":"https://github.com/sqlc-dev/sqlc/issues/3124"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:881e6733-a43e-1efb-85ef-a38395cf3492 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB50:34DB8F:1EE530F:293E425:6B017EC1 |
| html-safe-nonce | 427dc50f2fbe1e9e28bb3786cff713efaf2528c822fd5837b3970b12ef84c529 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjUwOjM0REI4RjoxRUU1MzBGOjI5M0U0MjU6NkIwMTdFQzEiLCJ2aXNpdG9yX2lkIjoiNzUyMzc2NzYzMTgxNjUyMzQ1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7e7422e528b2c66a0d4cd299f56fa6136215aaee31bd5643ac2903d8370970c1 |
| hovercard-subject-tag | issue:2074828627 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sqlc-dev/sqlc/3124/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1b5f40234e8c079b5b0b7e22a170846a8ba1e3eb9f2f62d7c83810304c20741d/sqlc-dev/sqlc/issues/3124 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1b5f40234e8c079b5b0b7e22a170846a8ba1e3eb9f2f62d7c83810304c20741d/sqlc-dev/sqlc/issues/3124 |
| og:image:alt | What do you want to change? I would like sqlc to provide an option to emitting //go:generate annotation on generated models file in order to let us auto-generate the extended codes using go generat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ktogo |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/sqlc-dev/sqlc git https://github.com/sqlc-dev/sqlc.git |
| octolytics-dimension-user_id | 136738596 |
| octolytics-dimension-user_login | sqlc-dev |
| octolytics-dimension-repository_id | 193160679 |
| octolytics-dimension-repository_nwo | sqlc-dev/sqlc |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 193160679 |
| octolytics-dimension-repository_network_root_nwo | sqlc-dev/sqlc |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width