Trait photon_indexer::migration::sea_orm::QuerySelect

source ·
pub trait QuerySelect: Sized {
    type QueryStatement;

Show 18 methods // Required method fn query(&mut self) -> &mut SelectStatement; // Provided methods fn select_only(self) -> Self { ... } fn column<C>(self, col: C) -> Self where C: ColumnTrait { ... } fn column_as<C, I>(self, col: C, alias: I) -> Self where C: IntoSimpleExpr, I: IntoIdentity { ... } fn columns<C, I>(self, cols: I) -> Self where C: ColumnTrait, I: IntoIterator<Item = C> { ... } fn offset(self, offset: u64) -> Self { ... } fn limit(self, limit: u64) -> Self { ... } fn group_by<C>(self, col: C) -> Self where C: IntoSimpleExpr { ... } fn having<F>(self, filter: F) -> Self where F: IntoCondition { ... } fn distinct(self) -> Self { ... } fn distinct_on<T, I>(self, cols: I) -> Self where T: IntoColumnRef, I: IntoIterator<Item = T> { ... } fn join(self, join: JoinType, rel: RelationDef) -> Self { ... } fn join_rev(self, join: JoinType, rel: RelationDef) -> Self { ... } fn join_as<I>(self, join: JoinType, rel: RelationDef, alias: I) -> Self where I: IntoIden { ... } fn join_as_rev<I>(self, join: JoinType, rel: RelationDef, alias: I) -> Self where I: IntoIden { ... } fn lock(self, lock_type: LockType) -> Self { ... } fn lock_shared(self) -> Self { ... } fn lock_exclusive(self) -> Self { ... }
}
Expand description

Constraints for any type that needs to perform select statements on a Model

Required Associated Types§

Required Methods§

source

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

Add the select SQL statement

Provided Methods§

source

fn select_only(self) -> Self

Clear the selection list

source

fn column<C>(self, col: C) -> Self
where C: ColumnTrait,

Add a select column

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

assert_eq!(
    cake::Entity::find()
        .select_only()
        .column(cake::Column::Name)
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."name" FROM "cake""#
);

Enum column will be casted into text (PostgreSQL only)

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

assert_eq!(
    lunch_set::Entity::find()
        .select_only()
        .column(lunch_set::Column::Tea)
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT CAST("lunch_set"."tea" AS text) FROM "lunch_set""#
);
assert_eq!(
    lunch_set::Entity::find()
        .select_only()
        .column(lunch_set::Column::Tea)
        .build(DbBackend::MySql)
        .to_string(),
    r#"SELECT `lunch_set`.`tea` FROM `lunch_set`"#
);
source

fn column_as<C, I>(self, col: C, alias: I) -> Self

Add a select column with alias

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

assert_eq!(
    cake::Entity::find()
        .select_only()
        .column_as(cake::Column::Id.count(), "count")
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT COUNT("cake"."id") AS "count" FROM "cake""#
);
source

fn columns<C, I>(self, cols: I) -> Self
where C: ColumnTrait, I: IntoIterator<Item = C>,

Select columns

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

assert_eq!(
    cake::Entity::find()
        .select_only()
        .columns([cake::Column::Id, cake::Column::Name])
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."id", "cake"."name" FROM "cake""#
);

Conditionally select all columns expect a specific column

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

assert_eq!(
    cake::Entity::find()
        .select_only()
        .columns(cake::Column::iter().filter(|col| match col {
            cake::Column::Id => false,
            _ => true,
        }))
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."name" FROM "cake""#
);

Enum column will be casted into text (PostgreSQL only)

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

assert_eq!(
    lunch_set::Entity::find()
        .select_only()
        .columns([lunch_set::Column::Name, lunch_set::Column::Tea])
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "lunch_set"."name", CAST("lunch_set"."tea" AS text) FROM "lunch_set""#
);
assert_eq!(
    lunch_set::Entity::find()
        .select_only()
        .columns([lunch_set::Column::Name, lunch_set::Column::Tea])
        .build(DbBackend::MySql)
        .to_string(),
    r#"SELECT `lunch_set`.`name`, `lunch_set`.`tea` FROM `lunch_set`"#
);
source

fn offset(self, offset: u64) -> Self

Add an offset expression

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

assert_eq!(
    cake::Entity::find()
        .offset(10)
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` OFFSET 10"
);
source

fn limit(self, limit: u64) -> Self

Add a limit expression

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

assert_eq!(
    cake::Entity::find()
        .limit(10)
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` LIMIT 10"
);
source

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

Add a group by column

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

assert_eq!(
    cake::Entity::find()
        .select_only()
        .column(cake::Column::Name)
        .group_by(cake::Column::Name)
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."name" FROM "cake" GROUP BY "cake"."name""#
);
source

fn having<F>(self, filter: F) -> Self
where F: IntoCondition,

Add an AND HAVING expression

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

assert_eq!(
    cake::Entity::find()
        .having(cake::Column::Id.eq(4))
        .having(cake::Column::Id.eq(5))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` HAVING `cake`.`id` = 4 AND `cake`.`id` = 5"
);
source

fn distinct(self) -> Self

Add a DISTINCT expression

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
struct Input {
    name: Option<String>,
}
let input = Input {
    name: Some("cheese".to_owned()),
};
assert_eq!(
    cake::Entity::find()
        .filter(
            Condition::all().add_option(input.name.map(|n| cake::Column::Name.contains(&n)))
        )
        .distinct()
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT DISTINCT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
);
source

fn distinct_on<T, I>(self, cols: I) -> Self
where T: IntoColumnRef, I: IntoIterator<Item = T>,

Add a DISTINCT ON expression NOTE: this function is only supported by sqlx-postgres

use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend};
struct Input {
    name: Option<String>,
}
let input = Input {
    name: Some("cheese".to_owned()),
};
assert_eq!(
    cake::Entity::find()
        .filter(
            Condition::all().add_option(input.name.map(|n| cake::Column::Name.contains(&n)))
        )
        .distinct_on([cake::Column::Name])
        .build(DbBackend::Postgres)
        .to_string(),
    "SELECT DISTINCT ON (\"name\") \"cake\".\"id\", \"cake\".\"name\" FROM \"cake\" WHERE \"cake\".\"name\" LIKE '%cheese%'"
);
source

fn join(self, join: JoinType, rel: RelationDef) -> Self

Join via RelationDef.

source

fn join_rev(self, join: JoinType, rel: RelationDef) -> Self

Join via RelationDef but in reverse direction. Assume when there exist a relation A to B. You can reverse join B from A.

source

fn join_as<I>(self, join: JoinType, rel: RelationDef, alias: I) -> Self
where I: IntoIden,

Join via RelationDef with table alias.

source

fn join_as_rev<I>(self, join: JoinType, rel: RelationDef, alias: I) -> Self
where I: IntoIden,

Join via RelationDef with table alias but in reverse direction. Assume when there exist a relation A to B. You can reverse join B from A.

source

fn lock(self, lock_type: LockType) -> Self

Select lock

source

fn lock_shared(self) -> Self

Select lock shared

source

fn lock_exclusive(self) -> Self

Select lock exclusive

Object Safety§

This trait is not object safe.

Implementors§