Skip to content

Type overriding does not work for uuid, causes import conflict #1984

Closed

Description

@utkarshod

Discussed in #1983

Originally posted by utkarshod December 4, 2022
I want to override the google uuid but when I try type overriding, it does not replace the google uuid but merely adds the new one to the imports of the models.go:

	"github.com/gofrs/uuid"
	"github.com/google/uuid"

This causes the following import error:

internal/queries/models.go:13:2: uuid redeclared in this block
	internal/queries/models.go:11:2: other declaration of uuid

I've tried version 1 (as following), version 2 and column overriding and yet I am unable to get the google uuid to stop being imported. Note: Type overriding works for me for another db type, just not uuid.

packages:
  - path: "internal/queries"
    name: "queries"
    engine: "postgresql"
    schema: "data/schema.sql"
    queries: "data/queries.sql"
    emit_methods_with_db_argument: true
    overrides:
      - go_type: "github.com/gofrs/uuid.UUID"
        db_type: "uuid"

This seems like a bug to me. Any suggestions / help would be greatly appreciated!

Activity

  1. mcdoker18 commented on Dec 4, 2022

    @mcdoker18
    Contributor

    Can you provide the reproducible example?

    Because the type overriding works https://play.sqlc.dev/p/26d5866a44400ad7b1a183cc8b43e4ecb691e76274fed0f01d7711a386b635e7

    If you need use both packages, you can specify package alias:

          "go_type": {
                "import": "github.com/gofrs/uuid",
                "package": "gofrsuuid",
                "type": "UUID",
                "pointer": true
              }
  2. utkarshod commented on Dec 4, 2022

    @utkarshod
    Author

    @mcdoker18 thanks so much for the response! That helped.

    The issue was that in my schema, I had one uuid and one uuid NOT NULL. And the latter was getting assigned the google uuid (example), resulting in 2 different uuid imports in models.go.

    But following your suggestion, I overrode both nullable and not nullable uuids like here, which solved the problem.

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