Make ordering consistent across all dialects#882
Conversation
|
What if we wanted to use literal strings for our custom functions? :P |
|
That is not supported with this scheme. We could say that cols are quoted, args are escaped, but what if we want to combine the two :P ? sparse arrays?: {
cols: [undefined, 'col1'],
args: ['string literal', undefined]
}to yield |
|
No, tbh I think we should have a small instace called SequelizeColumn or something and check it's instance? Something like I've been thinking about these kind of concepts for a long time but with the impementation of node-sql in Sequelize this may already exist (sort of / kind of). Either way I suppose we can worry about this later down the road when we start utilizing node-sql more :) |
|
Updated with the fn / col syntax suggested by @durango :) |
|
Muuuuuuuch better, this changes everything too btw :) I'll merge later tonight when I get off of work and/or tomorrow on my day off. |
Make ordering consistent across all dialects
This PR gives consistent ordering / grouping semantics across all dialects. It also provides support for multiple order columns for all dialects (closes #817 ) and support for functions in order / group by (closes #783)
The semantics are described below
The distinction is basically - if order / group is a single string, we leave it alone, if it is an array we handle each element. The logic for what to do with strings/arrays/objects is common to all dialects, so I've added that in the abstract QG (which has moved from being solely an interface def, to now containing one actual implementation, and a lot of interface defs)
Previously, a string passed to order would be escaped from pg, but not for mysql (as in id DESC would be "id" DESC for PG, but id desc for mysql). Now it is id DESC for all dialects, to allow for a way of passing a verbatim qoute string. This means that we slightly change semantics / backwards compat., but I would argue that it is okay in this case, for the sake of making the api consistent. Furthermore, two things can happen when the order string is no longer escaped in PG:
Futhermore, all grouping strings were escaped - I've removed that feature, to make the API consistent