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

Invalid UUID type is generated for null column with foreign key #3671

Open
illiafox opened this issue Oct 22, 2024 · 0 comments
Open

Invalid UUID type is generated for null column with foreign key #3671

illiafox opened this issue Oct 22, 2024 · 0 comments
Labels

Comments

@illiafox
Copy link

illiafox commented Oct 22, 2024

Version

1.27.0

What happened?

Generated models.go

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0

package repository

import (
	"github.com/google/uuid"
)

type Item struct {
	ID       uuid.UUID `db:"id"`
	ParentID uuid.UUID `db:"parent_id"`
	Name     string    `db:"name"`
}

I expect sqlc to generate ParentID *uuid.UUID, because this column is nullable

Relevant log output

No response

Database schema

CREATE TABLE IF NOT EXISTS items
(
    id         UUID PRIMARY KEY           DEFAULT uuid_generate_v4(),
    parent_id  UUID REFERENCES items (id) NULL,
    name TEXT NOT NULL
);

SQL queries

-- name: CreateItem :exec
INSERT INTO items (id, parent_id, name)
VALUES (@id,
        @parent_id,
        @name);

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "repository"
        out: "."
        sql_package: "pgx/v5"
        emit_all_enum_values: true
        emit_db_tags: true
        emit_interface: true
        emit_json_tags: true
        emit_prepared_queries: true
        emit_enum_valid_method: true
        emit_empty_slices: true
        emit_params_struct_pointers: true
        emit_result_struct_pointers: true
        emit_pointers_for_null_types: true
        json_tags_case_style: "snake"
        query_parameter_limit: 2
        overrides:
          - db_type: "uuid"
            go_type: "github.com/google/uuid.UUID"
          - db_type: "uuid"
            go_type: "github.com/google/uuid.UUID"
            nullable: true

Playground URL

https://play.sqlc.dev/p/5121c5319cdf6954e4bbfd00e098390d567401afe8cd5418ce9fb4217ac902c7

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant