Skip to content

Add order-by logic to database queries#491

Open
xelab04 wants to merge 3 commits intocot-rs:masterfrom
xelab04:db-sort-by
Open

Add order-by logic to database queries#491
xelab04 wants to merge 3 commits intocot-rs:masterfrom
xelab04:db-sort-by

Conversation

@xelab04
Copy link
Contributor

@xelab04 xelab04 commented Feb 24, 2026

Refer to #490

@github-actions github-actions bot added the C-lib Crate: cot (main library crate) label Feb 24, 2026
@xelab04
Copy link
Contributor Author

xelab04 commented Feb 24, 2026

https://docs.rs/sea-query/latest/sea_query/query/trait.OrderedStatement.html
The sea query docs make a reference to order_by_expr which takes expr: SimpleExpr, order: Order

I'm not exactly sure how to plug sea query into this?

@xelab04 xelab04 marked this pull request as draft February 24, 2026 17:00
@xelab04
Copy link
Contributor Author

xelab04 commented Feb 24, 2026

Right, updated it to use seaquery's own order_by method. I'm not getting the types down for the time being, will work on it more later.

@xelab04
Copy link
Contributor Author

xelab04 commented Mar 11, 2026

I have changed it so that instead of ordering on a string of the field name, it uses the fieldref identifier.
So, it would look something like this:

use cot::db::model;
use cot::db::query::Query;
use sea_query::Order; (?)

#[model]
struct User {
    #[model(primary_key)]
    id: i32,
    age: i32,
}

let query = Query::<User>::new().order_by(User::age, Order::Asc);

Last bit is the ownership because it's not happy with the .clone()
And of course, tests

@xelab04 xelab04 marked this pull request as ready for review March 11, 2026 09:18
@seqre seqre linked an issue Mar 23, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DB sort by method

1 participant