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:: All + Paginated + get_many queries lack "order by" #17

Closed
apps4uco opened this issue Oct 3, 2021 · 2 comments
Closed

Table:: All + Paginated + get_many queries lack "order by" #17

apps4uco opened this issue Oct 3, 2021 · 2 comments

Comments

@apps4uco
Copy link

apps4uco commented Oct 3, 2021

Firstly, thanks for a useful crate.

I have encountered an issue that seems to affect Table::all / all_paginated/ stream-all / stream_all_paginated / get_many. There appears to be no way currently to specify the order of the results and the order varies after updates or inserts, this makes the paginated functions not too useful. If I am mistaken could the documentation be changed to show how.

I am using postgres but as SQL does not guarantee an ordering for a select, this would apply to all databases. Sql standard states "If an is not specified, then the ordering of the rows of Q is implementation-dependent."

Would there be a way to specify at the Table level an "order by"

#[ormx(table = "...",order="id asc")]
or for several
#[ormx(table = "...",order="firstname asc, lastname asc")]

#[ormx(get_many,order="firstname asc, lastname asc"))]:

or if not then could you add an example to do order by, offset and limit using the conditional_query_as macro, and maybe clarify in the methods mentioned that the order is not guaranteed.

Thanks

@NyxCode
Copy link
Owner

NyxCode commented Oct 4, 2021

That's a good point!
So I think that ORDER BY id DESC would be an appropriate default ordering, but there needs to be a way of changing that.
Will work on this in the near future.

NyxCode added a commit that referenced this issue Sep 8, 2024
@NyxCode
Copy link
Owner

NyxCode commented Sep 8, 2024

Implemented in #40.
The default ordering is ORDER BY <id column> DESC, which can be overwritten using #[ormx(order_by = "...")]

@NyxCode NyxCode closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants