sqlc
sqlc copied to clipboard
Add support for emitting pointer types for nullable columns
pgx/v4 supports passing and scanning into pointer types for nullable columns instead of using the standard library Null<Type> representation, which is super handy if you wind up interfacing a lot with, say, generated Protocol Buffer files using the proto3 optional flag.
This PR adds a new configuration option emit_pointers_for_null_types, which, as per the documentation line added:
If true and
sql_packageis set topgx/v4, generated types for nullable types are emitted as pointers (ie.*string) instead ofdatabase/sqlnull types (ie.NullString). Defaults tofalse.
This change would be a significant quality-of-life improvement for me, but I obviously don't know if it generally fits with the philosophy of sqlc, so consider this a suggestion and please feel free to provide any feedback (including, but not limited to bike-shedding of the choice of name for the configuration parameter, if we see this feature fit for sqlc.)
Lastly, thanks all for building this tool. It's genuinely saved me tons of hours writing the same pesky boiler plate with limited guarantees.
how can I try this out? I have been looking at the alternative which is to manually override but that is pretty tedious. would like to try this out just don't know how to include it.
This was implemented before (named a bit differently), but it has been removed. #814 has a list of needed overrides. Which is a bit tedious to copy around I'd say.
@mvrhov so is it just recommend to add them manually then I'm guessing?
Thanks for this list as it does help.
For now I guess. I do like this PR because then I don't have to copy a bunch of lines into each project.
Certainly avoiding having to copying a bunch of lines around would be a huge improvement. Any chance this could be considered for a merge in your eyes, despite prior history, @mvrhov?
@nickbruun It's not my decision on what's getting merged.
@mvrhov I understand – mostly just wondering what historical context you can provide since it sounds like this was tried before?
@nickbruun Sorry that I'm just getting around to getting this reviewed. I know it's been months since it was opened.
I'm onboard with this change and would like to get it merged for the pgx/v5 release https://github.com/kyleconroy/sqlc/issues/1823
Let me review the changes from pgx/v5 and I'm happy to update in accordance :)
would be good to have this feature in v5
Is this going to be merged soon? I'm using sqlc, gqlgen and gqlgenc, getting an error about String is incompatible with database/sql.NullString and I'd much rather use the pointers for null types.
Oh wow, I totally got behind on developing a coherent view on pgx/v5. Thanks for merging this!