[−][src]Macro df_st_db::order_by
Creates a match condition on order_by
used for
sorting the database query.
Parameters:
order_by
:String
, variable used as a key.asc
:bool
, true is sorting by asc, false if desc.query
: First part of the Diesel query. (stored in variable)conn
:&DbConnection
, connection to database.key => value
: (first pair will be used as default)key
:&str
, name of the field that matches theorder_by
.value
: Diesel column, the column that matches the key. Return: The result of the database query, returned type has to be set outside. Example use:
ⓘ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)}, }?;