Open prust opened 9 years ago
If you want my 2 cents on it - trying to support everything with some structure is fools errand. Structure is only needed to be able to manipulate unfinished query. How many people really need to pass around partially ordered query to be able to add more order on it?
So if we accept that one doesn't need to refine order then we can just recommend to use sql()
for hard cases:
query.orderBy(sql('age desc, name collate Latin1_General_CI_AS'))
For simple cases current behavior is almost sufficient. The only case is simple direction flip is absent. Proposed .asc()
and .desc()
could do, but often when we decide on user input some parameterized method is better:
// .asc() and .desc()
var query = query.orderBy('name')
args.asc ? query.asc() : query.desc()
// order direction as param, chains better
query.orderBy('name').orderDir(args.asc)
// or
query.orderBy('name', args.asc)
My current thought (though I'm open on this) would be to support all the functionality via passing an array of objects to ORDER BY:
And to add .asc(), .desc() and .collate() convenience functions which augment the column most recently passed to .orderBy():
See #39 for more details.