#order #diesel #query

diesel-order-with-direction

Order diesel queries based on a direction parameter

6 releases

0.2.2 Dec 12, 2022
0.2.1 Dec 11, 2022
0.1.2 Dec 12, 2022

#2061 in Database interfaces

Download history 8/week @ 2023-12-18 13/week @ 2024-01-01 12/week @ 2024-02-19 9/week @ 2024-02-26 9/week @ 2024-03-11 16/week @ 2024-03-18 90/week @ 2024-03-25 127/week @ 2024-04-01

242 downloads per month

MIT license

11KB
164 lines

Diesel dynamic query ordering

This crate provides the OrderWithDirectionDsl trait for dynamic query ordering;

#[macro_use] extern crate diesel;
use diesel::mysql::Mysql;
use diesel::QueryDsl;
use diesel_order_with_direction::{OrderWithDirectionDsl, QueryOrderDirection};
table! {
    posts (id) {
        id -> Integer,
    }
}

let direction = QueryOrderDirection::Descending;

let query = posts::table
    .into_boxed::<Mysql>()
    .order_with_dir(direction, posts::id)
    .limit(5);

let query = posts::table
    .into_boxed::<Mysql>()
    .then_order_by_with_dir(direction, posts::id)
    .limit(5);

Dependencies

~2.5MB
~51K SLoC