Title: Ability to return an iterator on a "many" query · Issue #720 · sqlc-dev/sqlc · GitHub
Open Graph Title: Ability to return an iterator on a "many" query · Issue #720 · sqlc-dev/sqlc
X Title: Ability to return an iterator on a "many" query · Issue #720 · sqlc-dev/sqlc
Description: Hi, when a query return a myriad of objects, the slice based solution is not very efficient, it would be great if it was possible to have a way to return some kind of iterator on the rows, something like sql.Rows but type safe. The first...
Open Graph Description: Hi, when a query return a myriad of objects, the slice based solution is not very efficient, it would be great if it was possible to have a way to return some kind of iterator on the rows, somethin...
X Description: Hi, when a query return a myriad of objects, the slice based solution is not very efficient, it would be great if it was possible to have a way to return some kind of iterator on the rows, somethin...
Opengraph URL: https://github.com/sqlc-dev/sqlc/issues/720
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Ability to return an iterator on a \"many\" query","articleBody":"Hi, when a query return a myriad of objects, the slice based solution is not very efficient, it would be great if it was possible to have a way to return some kind of iterator on the rows, something like sql.Rows but type safe.\r\n\r\nThe first solution that comes to mind is to add a new type of function in the sql queries builder.\r\nInstead of writing `-- name: Name :many` we would write `-- name: Name :rows` or another relevant keyword\r\n\r\nand for the generated code, it would look something like this\r\n```sql\r\nCREATE TABLE pilots (\r\n id integer NOT NULL,\r\n name text NOT NULL\r\n);\r\n\r\nALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id);\r\n```\r\n```sql\r\n-- name: ListPilots :rows\r\nSELECT * FROM pilots;\r\n```\r\n```go\r\ntype Pilot struct {\r\n\tID int32\r\n\tName string\r\n}\r\n\r\ntype PilotRows struct {\r\n\trows *sql.Rows\r\n}\r\n\r\nfunc (p *PilotRows) Close() error {\r\n\treturn p.rows.Close()\r\n}\r\nfunc (p *PilotRows) Next() bool {\r\n\treturn p.rows.Next()\r\n}\r\nfunc (p *PilotRows) Scan(dest *Pilot) error {\r\n\treturn p.rows.Scan(dest.ID, dest.Name)\r\n}\r\nfunc (p *PilotRows) Err() error {\r\n\treturn p.rows.Err()\r\n}\r\n\r\nfunc (q *Queries) ListPilots(ctx context.Context) (*PilotRows, error) {\r\n\trows, err := q.query(ctx, q.listPilotsStmtn, listPilots)\r\n\tif err != nil {\r\n\t\treturn nil, err\r\n\t}\r\n\treturn \u0026PilotRows{rows: rows}, nil\r\n}\r\n\r\n```\r\n","author":{"url":"https://github.com/encendre","@type":"Person","name":"encendre"},"datePublished":"2020-09-27T04:11:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":22},"url":"https://github.com/720/sqlc/issues/720"}
| 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:6b83eeb6-54f0-86a1-2a0f-c289d56612c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B46C:185C34:6BE284:91C779:6A530281 |
| html-safe-nonce | 862fabb86bb22f4a00c75be83047e2c907423923815659cf9a0d6904d5e28537 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDZDOjE4NUMzNDo2QkUyODQ6OTFDNzc5OjZBNTMwMjgxIiwidmlzaXRvcl9pZCI6IjgwMDk0NjQ2NTI3MTgzNDI3ODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | bfbf5199cc9de67fb40f59c28c2f9eef87863edf3d32e61bea4aca339068ee97 |
| hovercard-subject-tag | issue:709662625 |
| 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/720/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93236ebab8754040c6715991db19e4b54c735086288d3871dd8db1f696afb18f/sqlc-dev/sqlc/issues/720 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93236ebab8754040c6715991db19e4b54c735086288d3871dd8db1f696afb18f/sqlc-dev/sqlc/issues/720 |
| og:image:alt | Hi, when a query return a myriad of objects, the slice based solution is not very efficient, it would be great if it was possible to have a way to return some kind of iterator on the rows, somethin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | encendre |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width