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

Table, Database, & Schema APIs should support sorting by ID & name #635

Closed
kgodey opened this issue Sep 7, 2021 · 5 comments · Fixed by #691
Closed

Table, Database, & Schema APIs should support sorting by ID & name #635

kgodey opened this issue Sep 7, 2021 · 5 comments · Fixed by #691
Assignees
Labels
type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL

Comments

@kgodey
Copy link
Contributor

kgodey commented Sep 7, 2021

Problem

The table, database, and schema APIs don't currently support sorting results.

Proposed solution

All three APIs should support sorting by ID and name.

Additional context

We can use django-filter / django-property-filter for this.

@kgodey kgodey added type: enhancement New feature or request help wanted Community contributors can implement this work: backend Related to Python, Django, and simple SQL ready Ready for implementation labels Sep 7, 2021
@kgodey kgodey added this to the 06. 2021-09 Stability milestone Sep 7, 2021
@bohemia420
Copy link
Contributor

can it be a simple KW supplied i.e
/api/v0/tables/2/columns?sort=-name for descending order w.r.t names?

Can I work on this?

@kgodey
Copy link
Contributor Author

kgodey commented Sep 27, 2021

@bohemia420 Sure, I'll assign it to you. Thanks!

The easiest thing would be to use django-filter's OrderingFilter: https://django-filter.readthedocs.io/en/stable/ref/filters.html?highlight=sort#orderingfilter

This should apply to:

  • /api/v0/tables/
  • /api/v0/schemas/
  • /api/v0/databases/

This issue doesn't cover adding filters to the columns API (e.g. /api/v0/tables/2/columns/)

bohemia420 added a commit to bohemia420/mathesar that referenced this issue Oct 4, 2021
…for Database, Schema, Table Filters to use (Property)OrderingFilter from django_(property)_filters
@bohemia420
Copy link
Contributor

Hi @kgodey
This looks done - I have tested it for all the specified api endpoints:

- /api/v0/tables/
- /api/v0/schemas/
- /api/v0/databases/

and it seems to sort the entries by either the field i.e "id" or the property i.e "name" (for schemas and tables). As of now, the capability is basis the assumptions:

  • In the Django API, the Label is set to a standard "Sort By" followed by drop-down options (id, id(desc), name, name(desc))
  • The ordering_param name is being inferred implicitly from the OrderingFilter variable name, set to sort_by.
  • As of now, ordering has been only accomplished for fields / properties "id" and "name".

For example,
http://0.0.0.0:8000/api/v0/schemas/?sort_by=-name
http://0.0.0.0:8000/api/v0/tables/?sort_by=name
http://0.0.0.0:8000/api/v0/databases/?sort_by=-id

Which can easily be reached from the "Filters" Modal inside django API http://0.0.0.0:8000/api/v0/.

Have raised a PR #691 for the same.

(note: Albeit have simply tested capabilities via Django API, than pytests giving coverage).

@kgodey
Copy link
Contributor Author

kgodey commented Oct 4, 2021

Thanks @bohemia420. I'll review the PR.

@kgodey kgodey added status: started and removed help wanted Community contributors can implement this ready Ready for implementation labels Oct 12, 2021
@kgodey kgodey modified the milestones: [06] 2021-10 Stability, [06A] 2021-10 improvements Oct 14, 2021
@kgodey kgodey assigned kgodey and silentninja and unassigned bohemia420 and kgodey Nov 2, 2021
kgodey added a commit that referenced this issue Nov 9, 2021
fixes #635; changes to api/filters.py for Database, Schema, Table Filters; (Property)OrderingFilter from django_(property)_filters
@silentninja silentninja reopened this Nov 9, 2021
@silentninja
Copy link
Contributor

Created a new bug fix issue for the failing test cases that got merged along with PR related to this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request work: backend Related to Python, Django, and simple SQL
Projects
No open projects
3 participants