Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlc generate invalid go querier code on mysql with uuid #2721

Closed
peczenyj opened this issue Sep 8, 2023 · 4 comments
Closed

sqlc generate invalid go querier code on mysql with uuid #2721

peczenyj opened this issue Sep 8, 2023 · 4 comments
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@peczenyj
Copy link

peczenyj commented Sep 8, 2023

Version

1.21.0

What happened?

I think I find the minimal example that trigger the issue

https://play.sqlc.dev/p/3f394572c6d70a7216ec7e62480985911ca70ad94ff72501fa19c23dc3700844

If I have a field named uuid, that is a varchar(36)

and I override all the columns *.uuid to use github.com/google/uuid.UUID

and I split model and querier files

and I have a query that uses more than one field (to force generate one composite struct type) and one of them is our uuid

it works fine with sqlc 1.20.0 but in the latest version

the generated code add an import on github.com/google/uuid.UUID in the querier, but it is not necessary on this specific file

and any validation such as go vet just point that we have an unused import

I am not sure if it happens with other databases or other types.

Relevant log output

$ go vet ./...
tutorial/models_sqlc.go:10:2: no required module provides package github.com/google/uuid; to add it:
	go get github.com/google/uuid

Database schema

CREATE TABLE authors (
  id   BIGINT  NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name text    NOT NULL,
  bio  text,
  uuid varchar(36)
);

SQL queries

-- name: FindAuthor :one
SELECT * FROM authors
WHERE name = ? AND uuid = ? LIMIT 1;

Configuration

version: 2
overrides:
  go:
    overrides:
      - db_type: "json"
        go_type:
          type: "[]byte" # workaround sqlc bug when reading null json columns
        nullable: true
      - column: "*.uuid"
        go_type: "github.com/google/uuid.UUID"

sql:
  - engine: "mysql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "tutorial"
        out: "tutorial"
        emit_db_tags: true
        emit_prepared_queries: true
        emit_interface: true
        emit_exact_table_names: false
        emit_empty_slices: false
        emit_exported_queries: true
        emit_json_tags: true
        emit_params_struct_pointers: false
        emit_methods_with_db_argument: false
        emit_enum_valid_method: true
        emit_all_enum_values: true
        json_tags_case_style: "camel"
        output_files_suffix: "_sqlc"
        output_db_file_name: "db_sqlc.go"
        output_models_file_name: "models_sqlc.go"
        output_querier_file_name: "querier_sqlc.go"
        rename:
          uuid: "UUID"

Playground URL

https://play.sqlc.dev/p/3f394572c6d70a7216ec7e62480985911ca70ad94ff72501fa19c23dc3700844

It does not support latest sqlc yet, it seems to return http error 500

What operating system are you using?

Linux

What database engines are you using?

MySQL

What type of code are you generating?

Go

@peczenyj peczenyj added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 8, 2023
@peczenyj
Copy link
Author

peczenyj commented Sep 8, 2023

Ouch I think it is the same as #2707

@andrewmbenton
Copy link
Collaborator

Yes I think this is resolved on main as of yesterday when we merged #2709.

If you're able to go install @main and still see this issue please reopen.

@andrewmbenton andrewmbenton closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
@peczenyj
Copy link
Author

peczenyj commented Sep 9, 2023

Yes I confirm, with sqlc@main the issue is fixed

@peczenyj
Copy link
Author

peczenyj commented Sep 9, 2023

any chance to release a v1.21.1 @andrewmbenton ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

No branches or pull requests

2 participants