Closed kaboc closed 3 years ago
Hi @kaboc !
Thanks for opening this issue! This feature has recently been added to postgrest-js
on this PR.
If you have the time, it would be great if you could add this feature, but no pressure though. If you don't have the band width, I can work on it over the weekend!
Hi @dshukertjr . I'll give it a try anyway and let you know if I have some difficulty.
@kaboc Amazing!
Feature request
Is your feature request related to a problem? Please describe.
I'd like to sort the records in the above table by both
updated_at
andcreated_at
. Below is the expected result.The records are sorted by
updated_at
in descending order with nulls at the end, and records with nulls inupdated_at
are sorted bycreated_at
in descending order.With SQL (the dialect of postgres), I can achieve this by writing the
ORDER BY
clause like below:It doesn't seem the package has support for this, but having looked at the source code, I found that it was not impossible although it wasn't very easy.
This is converted to:
So what I'd like to do is possible if I write the sorting conditions as follows:
This is too hacky to use with peace of mind. We need a better way.
Describe the solution you'd like
The solution may be to allow multiple settings to be passed to
order()
or to add a new method specialised for it.For setting multiple options, some methods of this package use a string parameter, like
or('status.eq.OFFLINE,username.eq.supabot')
, but it's not very elegant nor safe.It might be better to have a class like
Order
and pass the list of its objects.e.g.
Describe alternatives you've considered
I also tried using multiple
order()
s likeorder('updated_at).order('created_at')
but with no success. Should it actually work for my usage? It didn't give any error.If using it in such a way has no effects currently, it may be better to make it work for this in that it is more intuitive for users.
I'm not familiar with this sort of query builders because I usually write raw SQL queries in backend servers, so other people with more knowledge are likely to have better ideas.
Additional context
I wondered if I should file this issue here, or in either repository of supabase/supabase or supabase/postgrest. Does a change in the API for a specific language require that it is applied to the APIs for other languages?