NyxCode / ormx

bringing orm-like features to sqlx
MIT License
287 stars 32 forks source link

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

Closed apps4uco closed 5 days ago

apps4uco commented 2 years ago

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 commented 2 years ago

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 commented 5 days ago

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