Skip to content

feat: add order-by logic to database queries#491

Open
xelab04 wants to merge 6 commits into
cot-rs:masterfrom
xelab04:db-sort-by
Open

feat: add order-by logic to database queries#491
xelab04 wants to merge 6 commits into
cot-rs:masterfrom
xelab04:db-sort-by

Conversation

@xelab04

@xelab04 xelab04 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Refer to #490

@github-actions github-actions Bot added the C-lib Crate: cot (main library crate) label Feb 24, 2026
@xelab04

xelab04 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

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

xelab04 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

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

xelab04 commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

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
@seqre

seqre commented May 3, 2026

Copy link
Copy Markdown
Member

Hey @xelab04, how it's going with this PR? Do you need any help from us?

@ElijahAhianyo

Copy link
Copy Markdown
Contributor

Hey @xelab04, How's it going with this PR? We're thinking of getting this PR in for the next release planned for this week. I see this is mostly done, and if you don't mind, I would love to finish this if you don't have the time.

@xelab04

xelab04 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @ElijahAhianyo I had forgotten about this PR till recently because of a series of illnesses. My apologies.

Yes, I remember having mostly completed the PR, but was particularly stumped with creating the proper tests for it. I'd be really happy if you could complete it; I'll also use the opportunity to better understand how I should have done it.

I'm sorry it's been in draft for so long.

@ElijahAhianyo

ElijahAhianyo commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Hi @ElijahAhianyo I had forgotten about this PR till recently because of a series of illnesses. My apologies.

Yes, I remember having mostly completed the PR, but was particularly stumped with creating the proper tests for it. I'd be really happy if you could complete it; I'll also use the opportunity to better understand how I should have done it.

I'm sorry it's been in draft for so long.

Ah, no worries. I'll take this up from here and also wish you a speedy recovery. Thanks a lot for your contribution!

@seqre seqre changed the title Add order-by logic to database queries feat: add order-by logic to database queries Jul 6, 2026
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

4 participants