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

feat(sqlc): Support custom generic nullable types (i.e. sql.Null[string]) #3202

Closed
wants to merge 0 commits into from

Conversation

gregoryjjb
Copy link

@gregoryjjb gregoryjjb commented Feb 14, 2024

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]
}

I only use sqlite but I added support & tests for Postgres and MySQL.

The test cases use sql.Null even though the project isn't on Go 1.22 yet, but that doesn't seem to be an issue since the generated test package doesn't seem to be built/run anywhere?

nvm it has indeed been upgraded already.

nvm it was only upgraded in the Dockerfile. I'll make a dummy type for the tests.

@gregoryjjb gregoryjjb mentioned this pull request Feb 14, 2024
@gregoryjjb
Copy link
Author

I'm not supper happy about how this works (or rather doesn't work) with overrides. Ideally I would specify a custom override type without specifying its nullability, and then with this new option set it would wrap with the nullable type automatically (i.e. sql.Null[MyCustomOverride]).

@gregoryjjb
Copy link
Author

Superseded by #3279

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.

None yet

1 participant