sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.45k stars 804 forks source link

Convert use of sql.Null* types to sql.Null[T] #3689

Open Nigel2392 opened 1 week ago

Nigel2392 commented 1 week ago

What do you want to change?

Present

Currently all nullable types are generated as sql.NullInt, sql.NullBool, etc.

sql.Null

Using the sql.Null[T] generic type might be a relatively small, but very notable way to adress nullable SQL values.

Uniform Internals

This would likely also clean up the internals of SQLC for code- generation a bit, seeing as then values can simply be adressed with sql.Null.V, as opposed to sql.NullInt64.Int64, etc.

What database engines need to be changed?

PostgreSQL, MySQL, SQLite

What programming language backends need to be changed?

Go

ptman commented 1 week ago

I would allow that as an option, but prefer to user pointers myself.

Nigel2392 commented 1 week ago

I would allow that as an option, but prefer to user pointers myself.

I would also prefer to use pointers.

This is however only supported with the postgres engine, sql.Null[T] would provide a uniform way to adress values across multiple database engines with ease, allowing for more null types such as the uint types (and more).

I am not sure if this should be indeed an option:

  1. If it shouldn't be a config option the change should be well documented and it might break compatibility in certain setups/programs.
  2. If it is an option in the config; the point of this request is (in my opinion) very much negated. (Providing a clean and uniform way to adress values across database engines, while cleaning up SQLC internals.)