fix(knex): Fix Knex adapter date comparison queries #3429
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.
Summary
app.service('foo').find({ query: { closeTime: { $gt: new Date() } } })
just gets you all results.Other Information
The issue here is that a date is an object, so the code in knex/adapter tries to get the query operators as its keys and of course finds none so it just moves on. The fix here just lets a date be a date in comparisons, too.
Problem I of course want to include some unit tests for this. However, the typing in the tests somehow has been set up with
Omit
called on the enum for acceptable JSON Schema types - you can't make a json schema with a property that has{ type: 'date' }
to feed into the the query syntax, so it's impossible to construct a proper test involving dates. I'll 'fess up and admit that I tried to figure this out for several hours on Monday but couldn't.If someone who knows the codebase better than I do can point me to where
{ type: 'date' }
is ruled out by the typing in there I'll get this finished. Apologies for not finding it myself but that's how it is and I'm hoping someone with more knowledge than me can help me with it.Thanks! And thanks also to @daffl and all contributors for making the best of all API frameworks in any language!