The change to sql.Null. I'm struggling to see the benefits #437
Replies: 3 comments 14 replies
-
You make a lot of excellent points. I'll see if I can make the "default null system" configurable. |
Beta Was this translation helpful? Give feedback.
-
@stephenafamo what was the reasoning behind the move from I really liked the ergonomics of someSetter := &models.SomeSetter{
Foo: omit.From(foo),
NullableBar: omitnull.From(strings.ToLower(bar)),
BazBool: omit.From(false),
} Which now would need another wrapper anyway to get the pointers. someSetter := &models.SomeSetter{
Foo: PtrTo(foo),
NullableBar: PtrTo(sql.Null[string]{V: strings.ToLower(bar), Valid: true}),
BazBool: PtrTo(false),
} |
Beta Was this translation helpful? Give feedback.
-
This has been sort of reverted by #458
A |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
While I understand the desire to remove dependencies, are you sure this choice is the correct one?
While not entirely "idiomatic" go, I think the
omit
package has big benefits oversql.Null
and using pointers.Increased chance of nil panics
Since the
omit
packages forces you to check the content of null values, with theGet/MustGet
methods, it makes your code base much more safe against using nil/null values. The new way of relying on pointers makes, changes the explicit checks to something that the developer must think of implicitly, which I think is a worse pattern.Horrible JSON Marshalling
The
omit
package handles this beautifully.sql.Null
doesn't handle marshalling the way a developer expects. It simply marshalls the entire struct as can be seen here: golang/go#68375. Leading to JSON responses like this:With the new chance, every nullable value returned from
Bob
must be modified before it can be returned in an API. This is horrible DX compared to before.To be honest I'm struggling to see the small benefit of removing a dependency, outweighs the benefits of the
omit
library as illustrated in the two points above - and that is looking besides the fact that every Bob codebase must undertake huge refactors, which I can see past, since it's 0.X.X.However when the change only makes things worse, I think it is big mistake for
Bob
project to have made the change.Beta Was this translation helpful? Give feedback.
All reactions