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

Allow to override nullsfirst / nullslast in getList sort #160

Closed
fzaninotto opened this issue Aug 29, 2024 · 5 comments · Fixed by #164
Closed

Allow to override nullsfirst / nullslast in getList sort #160

fzaninotto opened this issue Aug 29, 2024 · 5 comments · Fixed by #164
Assignees
Labels
enhancement New feature or request

Comments

@fzaninotto
Copy link
Contributor

Problem

The getList implementation will use only asc or desc sort orders, while PostgREST supports additional options like desc.nullslast.

There is no simple wat to set nullsfirst or nullslast in a getList query without overriding the entire getList implementation

Solution

If the getList meta option contains nullsfirst or nullslast, append it to the sort order.

getList(
  'books',
  {
    pagination: { page: 1, perPage: 25 },
    sort: { field: 'published_at', order: 'DESC' },
  },
  { nullslast: true }
);
// GET /books?offset=0&limit=25&order=published_at.desc.nullslast
@scheiblr scheiblr added the enhancement New feature or request label Aug 30, 2024
@scheiblr scheiblr self-assigned this Aug 30, 2024
@scheiblr
Copy link
Collaborator

Thanks for stating this. I will look into this. Maybe, we could also implement it, so that it will be realizable by

getList(
  'books',
  {
    pagination: { page: 1, perPage: 25 },
    sort: { field: 'published_at', order: 'DESC.nullslast' },
  }
);
// GET /books?offset=0&limit=25&order=published_at.desc.nullslast

What do you think about that variant?

@fzaninotto
Copy link
Contributor Author

Unfortunately, TypeScript won't let you do that as I think the order field is typed 'ASC' | 'DESC'

@scheiblr
Copy link
Collaborator

I just saw in the code some mechanism for global setting: https://github.com/raphiniert-com/ra-data-postgrest?tab=readme-ov-file#null-sort-order

This is not an option for your use-case?

@fzaninotto
Copy link
Contributor Author

in my use case, yes I think it can work. I still think this should be supported on a per-query basis.

@fzaninotto
Copy link
Contributor Author

I tested the config and it doesn't work for getList (see #162)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants