Trait diesel::expression_methods::SortExpressionMethods [] [src]

pub trait SortExpressionMethods: Sized {
    fn nulls_first(self) -> NullsFirst<Self> { ... }
fn nulls_last(self) -> NullsLast<Self> { ... } }

Provided Methods

Specify that nulls should come before other values in this ordering. Normally, nulls come last when sorting in ascending order and first when sorting in descending order.

Example

connection.execute("CREATE TABLE foos (id SERIAL PRIMARY KEY, foo INTEGER)").unwrap();
connection.execute("INSERT INTO foos (foo) VALUES (NULL), (1), (2)").unwrap();

assert_eq!(Ok(vec![Some(1), Some(2), None]),
           foos.select(foo).order(foo.asc()).load(&connection));
assert_eq!(Ok(vec![None, Some(1), Some(2)]),
           foos.select(foo).order(foo.asc().nulls_first()).load(&connection));

Specify that nulls should come after other values in this ordering. Normally, nulls come last when sorting in ascending order and first when sorting in descending order.

Example

connection.execute("CREATE TABLE foos (id SERIAL PRIMARY KEY, foo INTEGER)").unwrap();
connection.execute("INSERT INTO foos (foo) VALUES (NULL), (1), (2)").unwrap();

assert_eq!(Ok(vec![None, Some(2), Some(1)]),
           foos.select(foo).order(foo.desc()).load(&connection));
assert_eq!(Ok(vec![Some(2), Some(1), None]),
           foos.select(foo).order(foo.desc().nulls_last()).load(&connection));

Implementors