Skip to content

Conversation

@gregoryjjb
Copy link

Support wrapping any nullable field with a generic type provided by the user. The config looks like this:

sql:
  - gen:
      go:
        ...
        generic_null_type:
          import: "database/sql"
          type: "Null"

and the generated models look like this:

type Foo struct {
	ID                    int64
	SometimesBlankText    sql.Null[string]
	SometimesBlankNumeric sql.Null[int64]
}

Adds github.com/LukaGiorgadze/gonull to testdata since the module isn't on Go 1.22 yet and thus can't use database/sql.Null. Upgrading it to 1.22 would probably be cleaner.

Supersedes #3202, closes #3149

@rouzier
Copy link
Contributor

rouzier commented Aug 21, 2024

When is this feature planned to be merged?

@YvanDaSilva
Copy link
Contributor

YvanDaSilva commented Feb 7, 2025

Are there any show stoppers ? @kyleconroy

@tomas-mraz
Copy link

Hi, I rebased Grag's feature branch to sqlc actual main and resolved conflicts here https://github.com/tomas-mraz/sqlc.git.
Can you @gregoryjjb rebase on your side to solve PR conflicts?
To easily solve conflicts during rebase, you can just copy /internal/codegen/golang/mysql_type.go from my fork.
Nice day

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

Labels

None yet

4 participants