-
Notifications
You must be signed in to change notification settings - Fork 6
feat: orderBy in the query builder #65
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
Conversation
|
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.
This looks fantastic!
One small change though is could we do sortBy instead of sortFn?
Maybe this is from too many years of using lodash haha. https://lodash.com/docs/#sortBy
I also don't tend to love variable names with postfixes for their type as long as we can make it obvious by its name which sortBy does.
Done, good call (I think I had I don't really expect people to use the |
Hmm though it's also confusing to have a config named sortBy and the SQL operator is orderBy 😂 Maybe comparator then as that's a typical name |
Yeah it's just for custom sorts right? Normally you wouldn't need it? |
The query engine adds a (currently named) When we construct the I think any of the three names would work. Aside: there is some internal tooling inherited from D2QL that would let the user name the |
Hmm so it's just a final sort on the sort already fine by d2ts? 🤔 Why make it an option at all then? |
The result collection could be sorted or not. It needs some way to know if it needs to sort the collection that has been returned. This could be a I went with Bare in mind that the output of the D2 pipeline is a series of changes, not a materialised list, so the internal sorted structure isn't accessible, thats why we annotate the results with the I agree, it seems confusing that the sort is potentially done twice, but with There is a lot of opportunity to refine and optimise all this - but I think getting the UX right first, then finding the optimisations later, makes the most sense. |
Can we completely keep the implementation internal? E.g. just the |
Yep, probably the easiest way is to look at the first item in the collection, and if it has an _orderByIndex do the sort. |
… _orderByIndex param
51ff256
to
bf2f007
Compare
@KyleAMathews I've changed this to use just infer that a collection should be sorted by looking for the |
The two errors in CI are the package reply due to the rename, and a formatting issue in the README - the latter is fixed in #66 |
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.
the result collections
.toArray
is ordered by the order by, and there is a_orderByIndex
prop on each result.This also updates the D2TS dep to a new version that fixes an issue in compaction that was apparent when doing an order by. This may also fix the issue @KyleAMathews saw with joins, as I think that was the same thing happening.