adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.96k stars 97 forks source link

Setting for forcing non-nullabillity #586

Open joleeee opened 1 month ago

joleeee commented 1 month ago

Describe the bug There should be a setting to force non-nullability of all parameters, and make nullability possibly opt in with the ? suffix. I don't really see the use case of nullability, but it has bit me in the back a few times so far because i forget to att the ! suffix.

See also #583 #118

https://github.com/adelsz/pgtyped/issues/118#issuecomment-652046970

Hi, thanks! Unfortunately, Postgres doesn't provide nullability information on parameter types, so we have to assume all parameters to be nullable by default.

This is not entirely true. We can also just assume they are not nullable. It would be less wrong imo. If you are not sure if something is nullable, better not assume it is.

joleeee commented 1 month ago

Wait, I'm even more confused now. How come i cannot pass null into a field which has the ! suffix? Does ! both mean that it has to be specified, and that it cannot be NULL? What if I want to force a field to be specified, but allow it to be null?

pnappa commented 1 month ago

What if I want to force a field to be specified, but allow it to be null?

Yeah, annoyingly things are marked as optional if they're allowed to be null. I've opened a PR to allow toggling the default behaviour of optional parameters here https://github.com/adelsz/pgtyped/pull/582 .

I do think there should be an option to make parameters not nullable by default too though!