-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add JSON serialization of filters for building more complex queries #113
Conversation
…ia POST Signed-off-by: Peter Broadhurst <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
========================================
Coverage 99.98% 99.98%
========================================
Files 77 78 +1
Lines 6170 6370 +200
========================================
+ Hits 6169 6369 +200
Misses 1 1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
…tMany Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
LessThanOrEqual []*FilterJSONKeyValue `ffstruct:"FilterJSON" json:"lessThanOrEqual,omitempty"` | ||
GreaterThan []*FilterJSONKeyValue `ffstruct:"FilterJSON" json:"greaterThan,omitempty"` | ||
GreaterThanOrEqual []*FilterJSONKeyValue `ffstruct:"FilterJSON" json:"greaterThanOrEqual,omitempty"` | ||
In []*FilterJSONKeyValues `ffstruct:"FilterJSON" json:"in,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the two biggest spelling discussions that could come out of this:
- do we want to spell these out or use abbreviations (many of these JSON query languages use "eq", "gt", etc)?
- do we want to provide a shortcut semantic for "not", such as prepending "n" or "!" or "not" to the operation name?
There isn't a ton of significance to it, because this is completely functional. But it's something we'll be using for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added shortcuts:
eq
neq
lt
nlt
gt
ngt
lte
nlte
gte
ngte
nin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seeing these written out, these seem redundant: nlt
ngt
nlte
ngte
(since they can all be more logically spelled as gte
lte
gt
lt
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But neq
and nin
seem useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing the ngts...
Might be worth some wider community input on the naming of the JSON filters... but overall this seems like a good direction. |
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with a few minor comments
Signed-off-by: Peter Broadhurst <[email protected]>
Signed-off-by: Peter Broadhurst <[email protected]>
Primary change
The URL query parameter spelling is designed to be convenient for simple cases, but it gets awkward with complex cases.
This PR proposes a JSON payload format and a utility to convert that into a runtime filter.
There are loads of ways this could be spelt (and many contrasting examples out there from other projects), with various compromises... the one I picked in this proposal was mainly for ease of implementation with our existing filtering code.
Some of the most significant choices/characteristics:
tag != 'abc'
is speltequal: [{not: true, field: "tag", value: "abc"}]
field
property - never a key nameAND
combination is the standard for all operator arrays, and when multiple operators usedOR
has to be specified explicitly, and the containing entries are all implicitAND
(although singulars are optimized out)Minor other proposals in PR
debug
logging to one line per SQL executionCRUD.GetMany()
where we still have two, but the 2nd includes the count returnedeventstreams
package to require IDs to be UUIDsExample (from test)
The AND/OR this results in