Title: Include getters and setters with models so we may work with interfaces instead of specific structs · Issue #2466 · sqlc-dev/sqlc · GitHub
Open Graph Title: Include getters and setters with models so we may work with interfaces instead of specific structs · Issue #2466 · sqlc-dev/sqlc
X Title: Include getters and setters with models so we may work with interfaces instead of specific structs · Issue #2466 · sqlc-dev/sqlc
Description: What do you want to change? Selecting all fields and a subset of fields for the same table yields different structs. Currently, we're required to write a mapper function which transforms the row(s) in to an abstraction our applications c...
Open Graph Description: What do you want to change? Selecting all fields and a subset of fields for the same table yields different structs. Currently, we're required to write a mapper function which transforms the row(s)...
X Description: What do you want to change? Selecting all fields and a subset of fields for the same table yields different structs. Currently, we're required to write a mapper function which transforms the ro...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/2466
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Include getters and setters with models so we may work with interfaces instead of specific structs","articleBody":"### What do you want to change?\r\n\r\nSelecting all fields and a subset of fields for the same table yields different structs. Currently, we're required to write a mapper function which transforms the row(s) in to an abstraction our applications can understand - however, if sqlc was to provide getters and setters, we'd be able to define interfaces which the results conform to and leave a lot of the heavy lifting to go.\r\n\r\nPlease see the example below:\r\n\r\n```sql\r\nCREATE TABLE `products`\r\n(\r\n `name` varchar(255) NOT NULL,\r\n `price` int(11) NOT NULL\r\n)\r\n```\r\n\r\n```go\r\n// generated models/queries\r\n\r\n// select * from products\r\ntype Product struct {\r\n Name string\r\n Price int\r\n}\r\nfunc (p Product) GetName() string { ... }\r\nfunc (p Product) GetPrice() int { ... }\r\n\r\n// select `name` from products\r\ntype ProductNameRow struct {\r\n Name string\r\n}\r\nfunc (p ProductNameRow) GetName() string { ... }\r\n\r\n// app\r\n\r\ntype ProductWithName interface {\r\n GetName() string\r\n}\r\n\r\nfunc DoesProductHaveCoolName[T ProductWithName](product T) bool { ... }\r\n\r\nDoesProductHaveCoolName(&ProductNameRow{}) // good\r\nDoesProductHaveCoolName(&Product{}) // also good\r\n```\r\n\r\nFor this particular problem extending the template for structs to include getters and setters would be sufficient, however - it may be a better idea to allow the extension of the template via the config file instead?\r\n\r\n### What database engines need to be changed?\r\n\r\nPostgreSQL, MySQL\r\n\r\n### What programming language backends need to be changed?\r\n\r\nGo","author":{"url":"https://github.com/blwsh","@type":"Person","name":"blwsh"},"datePublished":"2023-07-15T12:06:07Z","url":"https://github.com/sqlc-dev/sqlc/issues/2466"}
| 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:31280228-473d-4b6f-cfb1-a943f235fd9c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E284:158DF1:258C28:31A772:6B018BAC |
| html-safe-nonce | bcd73331d8d5a093300b0b9572362a4e7e7d0b54483ac21abc5aa83ceb1ba8ef |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjg0OjE1OERGMToyNThDMjg6MzFBNzcyOjZCMDE4QkFDIiwidmlzaXRvcl9pZCI6IjI4MTI0NzU3NjE0NDk2Njg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5b812dc5f1569d4ce5d1303c443038e4f194082827448d6967c09ea74188f520 |
| hovercard-subject-tag | issue:1806041276 |
| 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/2466/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3fee0059f1c3a188d4f079c6814a056e2a37692c80b9e59ae40374a057fdf1d6/sqlc-dev/sqlc/issues/2466 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3fee0059f1c3a188d4f079c6814a056e2a37692c80b9e59ae40374a057fdf1d6/sqlc-dev/sqlc/issues/2466 |
| og:image:alt | What do you want to change? Selecting all fields and a subset of fields for the same table yields different structs. Currently, we're required to write a mapper function which transforms the row(s)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | blwsh |
| 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