#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

#2990 in Database interfaces

25 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

~3MB
~62K SLoC