GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Ability to return an iterator on a "many" query · Issue #720 · sqlc-dev/sqlc

Ability to return an iterator on a "many" query #720

New issue
Copy link
New issue
Copy link
Open
Open
Ability to return an iterator on a "many" query#720
Copy link
Labels
enhancementNew feature or requestNew feature or request

Description

@encendre
encendre
opened on Sep 27, 2020
Issue body actions

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 solution that comes to mind is to add a new type of function in the sql queries builder.
Instead of writing -- name: Name :many we would write -- name: Name :rows or another relevant keyword

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

  1. kyleconroy
    added
    enhancementNew feature or requestNew feature or request
    on Oct 3, 2020
  2. kyleconroy
    added
    wontfixThis will not be worked onThis will not be worked on
    on Sep 12, 2021
  3. kyleconroy
    removed
    wontfixThis will not be worked onThis will not be worked on
    on Sep 22, 2023
  4. 23 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue 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.