Column comparisons & Fix unique index bug #847
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #636.
This introduces a new class of filters, that do comparisons on document level, instead of on property level.
The key use case is allowing column comparisons, e.g. fetch all tasks where task.foo > task.bar. The syntax is this:
I took care not to affect hot path's performance. So I don't do any
$$
checks — instead, all LokiOps now take a third argument (document) that's passed around - but only $$ops actually use it.Nested filters - $or, $and, $not, $len, $size, $elemMatch all work.
I'm also thinking of adding object-level $filter
.find({ $filter: (doc) => xxx })
and extending property-level $filter.find({ foo: { $filter: (foo, doc) => xxx } })
for object-level comparisons without having to completely resort to using.where()
. But I didn't do it in this PR.Additionally, I fix #839 here. Plain objects {} are not safe for use with arbitrary keys. Since Loki doesn't do ES6, I used prototype-less Objects to fix the issue.