Skip to content

Return types for queries #424

Open
Open

Description

@idruzhitskiy

Hello. Thank you for the library. I have a question though: in go's implementation of sqlc gen when working with queries such as SELECT * FROM users you get []User in code, same type for all results of selecting full data from users table. In this library each query gets its own *Row result, even in such cases. Is this intentional, can it be configured otherwise?

Activity

  1. doron050 commented on Oct 24, 2026

    @doron050
    Collaborator

    Hi, and thanks for the kind words!

    This is intentional, in the sense that it's how the generator is built today: every query that returns columns gets its own <QueryName>Row type, even when the columns are identical to a table's model. Unlike sqlc-gen-go, we don't detect that a query's result matches a table's columns and reuse the model. There's currently no option to change this.

    The only related feature is sqlc.embed(table), which makes the embedded part of the row use the existing model type (as a field inside the Row class).

    I agree that reusing the model for SELECT * queries would be nicer, since you could pass results around without mapping. It would make a good opt-in feature, so existing generated code doesn't get renamed. A possible design is an option (say reuseModelsForRows) that returns []User when a query's result columns match a table's columns exactly, the way sqlc-gen-go does.

    If that's something you'd use, I'm happy to take a look, or a PR is welcome. how would yo see this implemented?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions