sea_orm::query

Trait QueryOrder

Source
pub trait QueryOrder: Sized {
    type QueryStatement: OrderedStatement;

    // Required method
    fn query(&mut self) -> &mut SelectStatement;

    // Provided methods
    fn order_by<C>(self, col: C, ord: Order) -> Self
       where C: IntoSimpleExpr { ... }
    fn order_by_asc<C>(self, col: C) -> Self
       where C: IntoSimpleExpr { ... }
    fn order_by_desc<C>(self, col: C) -> Self
       where C: IntoSimpleExpr { ... }
    fn order_by_with_nulls<C>(
        self,
        col: C,
        ord: Order,
        nulls: NullOrdering,
    ) -> Self
       where C: IntoSimpleExpr { ... }
}
Expand description

Performs ORDER BY operations

Required Associated Typesยง

Required Methodsยง

Source

fn query(&mut self) -> &mut SelectStatement

Add the query to perform an ORDER BY operation

Provided Methodsยง

Source

fn order_by<C>(self, col: C, ord: Order) -> Self
where C: IntoSimpleExpr,

Add an order_by expression

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};

assert_eq!(
    cake::Entity::find()
        .order_by(cake::Column::Id, Order::Asc)
        .order_by(cake::Column::Name, Order::Desc)
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` ASC, `cake`.`name` DESC"
);
Source

fn order_by_asc<C>(self, col: C) -> Self
where C: IntoSimpleExpr,

Add an order_by expression (ascending)

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};

assert_eq!(
    cake::Entity::find()
        .order_by_asc(cake::Column::Id)
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` ASC"
);
Source

fn order_by_desc<C>(self, col: C) -> Self
where C: IntoSimpleExpr,

Add an order_by expression (descending)

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};

assert_eq!(
    cake::Entity::find()
        .order_by_desc(cake::Column::Id)
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` ORDER BY `cake`.`id` DESC"
);
Source

fn order_by_with_nulls<C>(self, col: C, ord: Order, nulls: NullOrdering) -> Self
where C: IntoSimpleExpr,

Add an order_by expression with nulls ordering option

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
use sea_query::NullOrdering;

assert_eq!(
    cake::Entity::find()
        .order_by_with_nulls(cake::Column::Id, Order::Asc, NullOrdering::First)
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."id", "cake"."name" FROM "cake" ORDER BY "cake"."id" ASC NULLS FIRST"#
);

Dyn Compatibilityยง

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementorsยง