Skip to content

Override query return type #781

Description

@reddec

Let's assume that we have two tables (postgres)

CREATE TABLE foo (
   id BIGSERIAL NOT NULL,
   value TEXT NOT NULL;
);

CREATE TABLE bar (
   id BIGSERIAL NOT NULL,
   value2 TEXT NOT NULL;
);

Problem is that queries

-- name: GetByFooValue :many
SELECT foo.id, bar.id, foo.value FROM foo INNER JOIN bar ON foo.id = bar.id WHERE value = $1

and

-- name: GetByBarValue :many
SELECT foo.id, bar.id, foo.value FROM foo INNER JOIN bar ON foo.id = bar.id WHERE value2 = $1

will generate different response structs (something like GetByBarValueRow and GetByFooValueRow), however by meaning it's the same objects.

I tried to use rename field in configuration but it didn't help. I quickly checked the source code and looks like there is no way to set the output type.

Is it possible to add something like:

  • use rename also for queries types or
  • (IMHO it's better) add an annotation to queries like name: GetByVarValue :type FooBar :many

Thanks!

Activity

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 request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions