You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The orderBy option does not allow you to specify more than one column to sort by. SQL itself lets you specify as many sorts as you want, and performs the sort as expected: sort records by the first column. If any of those values are the same, sort within those records by the second column, etc.
For example, sorting a list of contacts by last name and then by first name: contacts with the same last name will still be sorted alphabetically:
SELECT firstName
FROM contacts
ORDER BY lastName asc, firstName asc
Billy Bob
Aimee Cameron
Kate Cameron
Rob Cameron
John Doe
...
Suggested solution
Allow orderBy to accept an array of columns/directions to sort by which then passes them onto to SQL:
Some aspects are impossible to replicate: the results of the sorting are taken into account before returning a LIMIT, whcih you can't do outside of SQL—you'd need to return the entire result set and then sort on the client before knowing which records would be included in the cutoff and not.
If limiting isn't a concern, you could manually write some kind of multi-grouped sort that emulates what SQL already does natively.
Additional context
This is basic functionality provided by SQL, I don't a reason to arbitrarily restrict Prisma from using these features.
The text was updated successfully, but these errors were encountered:
Thanks @cannikin!
We have this one tracked here as well prisma/prisma-client-js#702
It's on the near term roadmap (that I'm busy putting together so we can publish it, stay tuned!) so something we'll likely support soon (think within 1-3 months, the sooner the better).
Problem
The
orderBy
option does not allow you to specify more than one column to sort by. SQL itself lets you specify as many sorts as you want, and performs the sort as expected: sort records by the first column. If any of those values are the same, sort within those records by the second column, etc.For example, sorting a list of contacts by last name and then by first name: contacts with the same last name will still be sorted alphabetically:
Suggested solution
Allow orderBy to accept an array of columns/directions to sort by which then passes them onto to SQL:
db.user.findMany({ orderBy: [{lastName: 'asc'}, {firstName: 'asc}] })
Alternatives
Some aspects are impossible to replicate: the results of the sorting are taken into account before returning a
LIMIT
, whcih you can't do outside of SQL—you'd need to return the entire result set and then sort on the client before knowing which records would be included in the cutoff and not.If limiting isn't a concern, you could manually write some kind of multi-grouped sort that emulates what SQL already does natively.
Additional context
This is basic functionality provided by SQL, I don't a reason to arbitrarily restrict Prisma from using these features.
The text was updated successfully, but these errors were encountered: