-
Notifications
You must be signed in to change notification settings - Fork 30
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
Query Sorting #57
Query Sorting #57
Conversation
@fonkadelic Backend requirements never cease to surprise 😆 Instead of sorting, maybe we should just respect the ordering of both the parsed/printed query string. This would require changing the |
I already gave it a try to use an array instead of of a dictionary. But i immediately got stuck since a lot of parts rely heavily on dictionary features. I'm really struggling when it comes to things like the The only thing that comes to my mind would be an |
@stephencelis @mbrandonw Additional feedback from your side would be highly appreciated in order to move forward here. |
@fonkadelic Sorry about that! We totally lost track of this issue. We are both OK with introducing |
@stephencelis No worries! I've swapped out the One thing i would like to discuss though is the fact that printing query items will happen in reverse order (due to the builder syntax): let p = Query {
Field("a")
Field("b")
Field("c")
}
let data = try p.print(("1", "2", "3"))
print(data.query) // ["c": ["3"], "b": ["2"], "a": ["1"]] I've noticed this is essentially the same problem that the |
@fonkadelic I think this is more due to the fact that parser printers should print via prepending when doing so into collections. Now that we don't sort automatically, we should be more careful. In particular, I believe this line should be updated:
To this: try input.fields.updateValue(
forKey: input.isNameCaseSensitive ? self.name : self.name.lowercased(),
insertingDefault: [],
at: 0,
with: { $0.prepend(try self.valueParser.print(output)) }
) Which will preserve the expected order. The name case sensitivity behavior of I think this issue already exists, though, and doesn't need to block this PR. Wanna try the above code snippet and see if that fixes things? |
@stephencelis Looking good. Thanks for the push in this direction. |
Thanks! |
This addresses an issue i've came across by using a list of query items with the following format:
As soon as the list grows to 10+ elements the result looks like this:
Since certain backends require a specific order of the query items especially when it comes to list indices it's probably a good idea to use a different comparison function for the sorting.
I've introduced a comparator on
URLQueryItem
which is basically just an alias for a string comparison function that respects number values. It can be reused across the library to get a consistent sorting behavior.