#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

#2056 in Database interfaces

30 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