Skip to content
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

Finish ORDER BY support: ASC, DESC & collations #73

Open
prust opened this issue Aug 26, 2015 · 1 comment
Open

Finish ORDER BY support: ASC, DESC & collations #73

prust opened this issue Aug 26, 2015 · 1 comment

Comments

@prust
Copy link
Collaborator

prust commented Aug 26, 2015

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:

.orderBy({column: 'age', order: 'DESC'}, {column: 'name', collate: 'Latin1_General_CI_AS'})

And to add .asc(), .desc() and .collate() convenience functions which augment the column most recently passed to .orderBy():

.orderBy('age').desc().orderBy('name').collate('Latin1_General_CI_AS')

See #39 for more details.

@Suor
Copy link
Contributor

Suor commented Oct 6, 2015

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants