-
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
I am querying a db table with many rows. I want to filter by a field, then get the 5 objects with the greatest values. I was thinking something like this, to get the 5 oldest people above the age of 18:
#[model]
pub struct person {
#[model(primary_key)]
pub id: Auto<i32>,
pub age: i32
}
// ...
let mut oldest_five = Query::<Article>::new();
let oldest_five = oldest_five
.filter(Expr::gt( Expr::field("age"), Expr::value(18) ))
.order(Expr::asc( Expr::field("age") ))
.limit(5)
.all(db)
.await?If I had to get all fields, then sort them within the Rust code and not the db query, I could risk high RAM usage. Also with the risk of less readable/fluent code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed