sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

feat(sqlc): Support custom generic nullable types (e.g. `sql.Null`)

Open gregoryjjb opened this issue 1 year ago • 1 comments

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

gregoryjjb avatar Mar 17 '24 20:03 gregoryjjb

When is this feature planned to be merged?

rouzier avatar Aug 21 '24 14:08 rouzier

Are there any show stoppers ? @kyleconroy

YvanDaSilva avatar Feb 07 '25 10:02 YvanDaSilva

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

tomas-mraz avatar Aug 07 '25 07:08 tomas-mraz