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 11 months 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