Closed zitnik closed 8 months ago
Totals | |
---|---|
Change from base Build 5418911557: | 0.6% |
Covered Lines: | 362 |
Relevant Lines: | 375 |
@zitnik @nikicc I just released the new version v2.4.2 to include this PR, you can give it a check. π
So grateful for your contributions. π
Imported the new version to our project, seems to do the trick :slightly_smiling_face:
@pilagod thank you for the review and for maintaining the library :muscle:
This PR aims to add support for NULL value replacement in custom types. Builds upon #39 and #44.
Current issue
The issue that I came across with the current implementation is that when the pagination cursor includes
null
for a custom type, that value is not properly replaced with theNullReplacement
value. The reason is that the Go-representation of the cursor value is not nil, but a custom type object (with an underlying value of nil).This in turn causes the pagination WHERE clause to compare the COALESCEd values of the target column with an unreplaced NULL, e.g.
WHERE COALESCE(my_attr, '') > NULL
.Implementation
The change in this PR specifically handles custom types in the
isNil
function so that for custom types we evaluateisNil
on the underlying value retrieved byGetCustomTypeValue
instead of on the object itself.Test
In order to construct a test, I added a custom type as an alias of
sql.NullString
, implemented the necessary methods on this type, and added a new field to theorder
struct. I guess this is a bit clumsy, in case you have any ideas about how to construct such a test more compactly, please let me know :) In the test itself, we have a primary pagination rule on "Remark" and a secondary rule on the new "Description" field so that the NULL element (ID 2) appears in the cursor causing the described problem.