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 — Ability to return an iterator on a "many" query · Issue #720 · sqlc-dev/sqlc Open Labels enhancementNew feature or requestNew feature or request DescriptionHi, 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 solution that comes to mind is to add a new type of function in the sql queries builder. and for the generated code, it would look something like this CREATE TABLE pilots ( id integer NOT NULL, name text NOT NULL ); ALTER TABLE pilots ADD CONSTRAINT pilot_pkey PRIMARY KEY (id); -- name: ListPilots :rows SELECT * FROM pilots; type Pilot struct { ID int32 Name string } type PilotRows struct { rows *sql.Rows } func (p *PilotRows) Close() error { return p.rows.Close() } func (p *PilotRows) Next() bool { return p.rows.Next() } func (p *PilotRows) Scan(dest *Pilot) error { return p.rows.Scan(dest.ID, dest.Name) } func (p *PilotRows) Err() error { return p.rows.Err() } func (q *Queries) ListPilots(ctx context.Context) (*PilotRows, error) { rows, err := q.query(ctx, q.listPilotsStmtn, listPilots) if err != nil { return nil, err } return &PilotRows{rows: rows}, nil } Reacted by Nathaniel Kofalt Activity
MetadataMetadataAssigneesLabelsenhancementNew feature or requestNew feature or request TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| 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. |