-
Notifications
You must be signed in to change notification settings - Fork 213
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: omitempty and omitnil struct tags #309
feat: omitempty and omitnil struct tags #309
Conversation
@doug-martin I planned to run CI workflows before marking ready to review, so if you are happy to approve running workflows that would be awesome :) |
Codecov Report
@@ Coverage Diff @@
## master #309 +/- ##
=======================================
Coverage 96.89% 96.90%
=======================================
Files 62 62
Lines 3477 3485 +8
=======================================
+ Hits 3369 3377 +8
Misses 92 92
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
I feel this is in reasonable shape to review. The coverage is down due to an existing uncovered path which I think should be unreachable. Happy to resolve if preferable, but it means we need to expose that logic outside the package and I’m not sure it’s worthwhile. |
Any updates on this? Would be a useful feature to get this merged. |
Would be keen to know the progress on this? |
This should be taken imo |
Dear @funkyshu Do you have time to take a look at other PRs? Seems this project doesn't have any other maintainers, and no others have privilege to update repo. |
There are a couple of open issues which I think would be most elegantly resolved by the introduction of
omitempty
and/oromitnil
struct tags: #174, #234. This PR introduces both tags.This provides for much greater flexibility when handling partial inserts or updates. For example, we may handle a partial update as a struct of pointers, where null values are not to be updated.
1.
omitnil
Output before this PR:
Output after this PR:
2.
omitempty
Output before this PR:
Output after this PR:
3. Discussion Items
util.IsEmptyValue
. Previously it did NOT return true for zero structs. The new implementation usesreflect.IsZero
which returns true for zero structs.omitempty
to work with structs that implement theValuer
interface (likeNullString
) in the way we'd expect - ie. aValuer
without a value should be omitted.defaultifempty
to work similarly with these structs, which will change the behaviour of existing code if anyone annotatedValuer
struct fields previously.util.IsEmptyValue
was previously implemented as it was, but am very open to feedback if I missed something or if the retrospective behaviour change is undesirable.*_example_test.go
tests are more extensive than the examples included in documentation. I thought this was the cleanest place to put the extra tests.