Skip to content

fix(schema): handle driver convertible slices - #7848

Open
zacharyarnaise wants to merge 1 commit into
go-gorm:masterfrom
zacharyarnaise:buildcond_values
Open

zacharyarnaise wants to merge 1 commit into
go-gorm:masterfrom
zacharyarnaise:buildcond_values

Conversation

@zacharyarnaise

Copy link
Copy Markdown
  • Do only one thing
  • Non breaking API changes
  • Tested

go-gorm/playground#859
Closes #7842

What did this pull request do?

This PR fixes Statement.BuildCondition to treat a slice that database/sql converts to a single driver value as one primary key instead of expanding it into an IN list.
Types that are genuinely a list (e.g. []string) keeps the IN (...) semantic.

Go 1.27 stdlib introduced uuid.UUID. Using it as an inline PK condition currently expands it and gives this:

SELECT * FROM "books" WHERE "books"."id" IN ($1,$2,...,$16) ORDER BY "books"."id" LIMIT 1

With this PR, it gives:

SELECT * FROM "books" WHERE "books"."id" = $1

User Case Description

Being able to use Go 1.27 uuid.UUID without having to wrap it in a type that implements driver.Valuer and sql.Scanner.
uuid.UUID implements neither but database/sql treats it as a special case, so values convert and scan on their own.
See:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can we use Go 1.27 UUID with GORM & GORM CLI?

1 participant