[][src]Macro df_st_db::order_by

macro_rules! order_by {
    { $order_by:ident, $asc:ident, $query:ident, $conn:ident,
      $default_key:expr => $default_variable:ident,
      $($key:expr => $variable:ident),* $(,)* } => { ... };
}

Creates a match condition on order_by used for sorting the database query. Parameters:

This example is not tested
let result: Vec<Region> = order_by!{
    order_by, asc, query, conn,
    "id" => id,
    "name" => name,
    "type" => type_,
    "evilness" => evilness,
};

Example generated code output:

This example is not tested
let result: Vec<Region> = match order_by.as_ref() {
    "name" => if asc {query.order(name.asc()).load(conn)}
        else {query.order(name.desc()).load(conn)},
    "type" => if asc {query.order(type_.asc()).load(conn)}
        else {query.order(type_.desc()).load(conn)},
    "evilness" => if asc {query.order(evilness.asc()).load(conn)}
        else {query.order(evilness.desc()).load(conn)},
    _ => if asc {query.order(id.asc()).load(conn)}
        else {query.order(id.desc()).load(conn)},
}?;