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 not working with datatype UUID #2720

Closed
mbe81 opened this issue Sep 8, 2023 · 2 comments
Closed

sqlc not working with datatype UUID #2720

mbe81 opened this issue Sep 8, 2023 · 2 comments
Labels
📚 mariadb bug Something isn't working upstream Issue is caused by a dependency

Comments

@mbe81
Copy link

mbe81 commented Sep 8, 2023

Version

1.21.0

What happened?

Since MariaDB 10.7 there is a native UUID data type. Using this data type in the schema definition gives an error when generating code:

sqlc generate failed.
# package db
query.sql:2:9: syntax error near "uuid primary key,"

Workaround

When I change the datatype in the schema.sql from uuid to binary and add an override in the sqlc.yaml the generation works as expected.

updated schema.sql:

create table user (
	id binary default uuid() not null primary key,
	name varchar(50) not null,
	email varchar(255) not null,
	password_hash varchar(60) not null,
	created_datetime timestamp not null default current_timestamp(),
	updated_datetime timestamp not null default current_timestamp() on update current_timestamp()
);

updated sqlc.yaml:

overrides:
  go:
    overrides:
      - db_type: "binary"
        nullable: false
        engine: "mysql"
        go_type:
          import: "github.com/google/uuid"
          type: "UUID"

However, changing the data type in the schema.sql is not desired because it does not reflect reality.


Database schema

create table user (
	id uuid default uuid() not null primary key,
	name varchar(50) not null,
	email varchar(255) not null,
	password_hash varchar(60) not null,
	created_datetime timestamp not null default current_timestamp(),
	updated_datetime timestamp not null default current_timestamp() on update current_timestamp()
);

SQL queries

-- name: listUsers :many
select * from user;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "mysql",
      "schema": "schema.sql",
      "queries": "queries.sql"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/e7301e06df354e56281efe68b535030621c6432705b11e54f542b1e322241858

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

@mbe81 mbe81 added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 8, 2023
@kyleconroy kyleconroy added upstream Issue is caused by a dependency 📚 mariadb and removed triage New issues that hasn't been reviewed labels Sep 8, 2023
@peczenyj
Copy link

peczenyj commented Sep 8, 2023

we had another issue with uuid on this version.

sqlc is trying to add the import github.com/google/uuid on the generated file querier_sqlc.go but this file does not use it directly - it just define the Querier interface and the go vet goes crazy.

we will try to write a minimal example that trigger this issue

@andrewmbenton
Copy link
Collaborator

@peczenyj the Querier imports issue was resolved in #2709.

Regarding sqlc support for MariaDB's custom UUID type, I don't think we can add that without introducing a new engine. There may be a point at which there are enough differences between MySQL and MariaDB where we want to introduce a new engine type, and maybe that point is already here. I'm not an expert so can't really say, but this is probably a conversation better handled in a GitHub discussion.

@andrewmbenton andrewmbenton closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 mariadb bug Something isn't working upstream Issue is caused by a dependency
Projects
None yet
Development

No branches or pull requests

4 participants