ColumnTrait

Trait ColumnTrait 

Source
pub trait ColumnTrait:
    IdenStatic
    + Iterable
    + FromStr {
    type EntityName: EntityName;

Show 42 methods // Required method fn def(&self) -> ColumnDef; // Provided methods fn enum_type_name(&self) -> Option<&'static str> { ... } fn entity_name(&self) -> DynIden { ... } fn as_column_ref(&self) -> (DynIden, DynIden) { ... } fn eq<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn ne<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn gt<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn gte<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn lt<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn lte<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn between<V>(&self, a: V, b: V) -> Expr where V: Into<Value> { ... } fn not_between<V>(&self, a: V, b: V) -> Expr where V: Into<Value> { ... } fn like<T>(&self, s: T) -> Expr where T: IntoLikeExpr { ... } fn not_like<T>(&self, s: T) -> Expr where T: IntoLikeExpr { ... } fn ilike<T>(&self, s: T) -> Expr where T: IntoLikeExpr { ... } fn not_ilike<T>(&self, s: T) -> Expr where T: IntoLikeExpr { ... } fn starts_with<T>(&self, s: T) -> Expr where T: Into<String> { ... } fn ends_with<T>(&self, s: T) -> Expr where T: Into<String> { ... } fn contains<T>(&self, s: T) -> Expr where T: Into<String> { ... } fn max(&self) -> Expr { ... } fn min(&self) -> Expr { ... } fn sum(&self) -> Expr { ... } fn avg(&self) -> Expr { ... } fn count(&self) -> Expr { ... } fn is_null(&self) -> Expr { ... } fn is_not_null(&self) -> Expr { ... } fn if_null<V>(&self, v: V) -> Expr where V: Into<Value> { ... } fn is_in<V, I>(&self, v: I) -> Expr where V: Into<Value>, I: IntoIterator<Item = V> { ... } fn is_not_in<V, I>(&self, v: I) -> Expr where V: Into<Value>, I: IntoIterator<Item = V> { ... } fn eq_any<V, I>(&self, v: I) -> Expr where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V> { ... } fn in_subquery(&self, s: SelectStatement) -> Expr { ... } fn not_in_subquery(&self, s: SelectStatement) -> Expr { ... } fn array_contains<V, I>(&self, v: I) -> Expr where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V> { ... } fn array_contained<V, I>(&self, v: I) -> Expr where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V> { ... } fn array_overlap<V, I>(&self, v: I) -> Expr where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V> { ... } fn into_expr(self) -> Expr { ... } fn into_returning_expr(self, db_backend: DbBackend) -> Expr { ... } fn select_as(&self, expr: Expr) -> Expr { ... } fn select_enum_as(&self, expr: Expr) -> Expr { ... } fn save_as(&self, val: Expr) -> Expr { ... } fn save_enum_as(&self, val: Expr) -> Expr { ... } fn json_key(&self) -> &'static str { ... }
}
Expand description

API for working with a Column. Mostly a wrapper of the identically named methods in sea_query::Expr

Required Associated Types§

Required Methods§

Source

fn def(&self) -> ColumnDef

Get the column definition with SQL attributes

Provided Methods§

Source

fn enum_type_name(&self) -> Option<&'static str>

Get the enum type name if this is a enum column

Source

fn entity_name(&self) -> DynIden

Get the name of the entity the column belongs to

Source

fn as_column_ref(&self) -> (DynIden, DynIden)

Get the table.column reference

Source

fn eq<V>(&self, v: V) -> Expr
where V: Into<Value>,

Perform equality against a Value. None will be converted to IS NULL.

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

assert_eq!(
    fruit::Entity::find()
        .filter(fruit::COLUMN.cake_id.eq(2))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `fruit`.`cake_id` = 2"
);
assert_eq!(
    fruit::Entity::find()
        .filter(fruit::COLUMN.cake_id.eq(Option::<i32>::None))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `fruit`.`cake_id` IS NULL"
);
Source

fn ne<V>(&self, v: V) -> Expr
where V: Into<Value>,

Perform inequality against a Value. None will be converted to IS NOT NULL.

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

assert_eq!(
    fruit::Entity::find()
        .filter(fruit::COLUMN.cake_id.ne(2))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `fruit`.`cake_id` <> 2"
);
assert_eq!(
    fruit::Entity::find()
        .filter(fruit::COLUMN.cake_id.ne(Option::<i32>::None))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `fruit`.`id`, `fruit`.`name`, `fruit`.`cake_id` FROM `fruit` WHERE `fruit`.`cake_id` IS NOT NULL"
);
Source

fn gt<V>(&self, v: V) -> Expr
where V: Into<Value>,

Source

fn gte<V>(&self, v: V) -> Expr
where V: Into<Value>,

Source

fn lt<V>(&self, v: V) -> Expr
where V: Into<Value>,

Source

fn lte<V>(&self, v: V) -> Expr
where V: Into<Value>,

Source

fn between<V>(&self, a: V, b: V) -> Expr
where V: Into<Value>,

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Id.between(2, 3))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` BETWEEN 2 AND 3"
);
Source

fn not_between<V>(&self, a: V, b: V) -> Expr
where V: Into<Value>,

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Id.not_between(2, 3))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`id` NOT BETWEEN 2 AND 3"
);
Source

fn like<T>(&self, s: T) -> Expr
where T: IntoLikeExpr,

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.like("cheese"))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE 'cheese'"
);
Source

fn not_like<T>(&self, s: T) -> Expr
where T: IntoLikeExpr,

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.not_like("cheese"))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` NOT LIKE 'cheese'"
);
Source

fn ilike<T>(&self, s: T) -> Expr
where T: IntoLikeExpr,

Postgres Only.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.ilike("cheese"))
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."name" ILIKE 'cheese'"#
);
Source

fn not_ilike<T>(&self, s: T) -> Expr
where T: IntoLikeExpr,

Postgres Only.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.not_ilike("cheese"))
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."name" NOT ILIKE 'cheese'"#
);
Source

fn starts_with<T>(&self, s: T) -> Expr
where T: Into<String>,

This is a simplified shorthand for a more general like method. Use like if you need something more complex, like specifying an escape character.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.starts_with("cheese"))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE 'cheese%'"
);
Source

fn ends_with<T>(&self, s: T) -> Expr
where T: Into<String>,

This is a simplified shorthand for a more general like method. Use like if you need something more complex, like specifying an escape character.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.ends_with("cheese"))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese'"
);
Source

fn contains<T>(&self, s: T) -> Expr
where T: Into<String>,

This is a simplified shorthand for a more general like method. Use like if you need something more complex, like specifying an escape character.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Name.contains("cheese"))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE `cake`.`name` LIKE '%cheese%'"
);
Source

fn max(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn min(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn sum(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn avg(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn count(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn is_null(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn is_not_null(&self) -> Expr

See also SeaQuery’s method with same name.

Source

fn if_null<V>(&self, v: V) -> Expr
where V: Into<Value>,

Provide fallback value if the column is null (null coalescing)

Source

fn is_in<V, I>(&self, v: I) -> Expr
where V: Into<Value>, I: IntoIterator<Item = V>,

Source

fn is_not_in<V, I>(&self, v: I) -> Expr
where V: Into<Value>, I: IntoIterator<Item = V>,

Source

fn eq_any<V, I>(&self, v: I) -> Expr
where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V>,

Available on crate feature postgres-array only.

Postgres only.

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

assert_eq!(
    cake::Entity::find()
        .filter(cake::Column::Id.eq_any(vec![4, 5]))
        .build(DbBackend::Postgres)
        .to_string(),
    r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = ANY(ARRAY [4,5])"#
);
Source

fn in_subquery(&self, s: SelectStatement) -> Expr

Source

fn not_in_subquery(&self, s: SelectStatement) -> Expr

Source

fn array_contains<V, I>(&self, v: I) -> Expr
where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V>,

Available on crate feature postgres-array only.

Array operator. Postgres only.

Source

fn array_contained<V, I>(&self, v: I) -> Expr
where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V>,

Available on crate feature postgres-array only.

Array operator. Postgres only.

Source

fn array_overlap<V, I>(&self, v: I) -> Expr
where V: Into<Value> + ValueType + NotU8, I: IntoIterator<Item = V>,

Available on crate feature postgres-array only.

Array operator. Postgres only.

Source

fn into_expr(self) -> Expr

Construct a Expr::Column wrapped in Expr.

Source

fn into_returning_expr(self, db_backend: DbBackend) -> Expr

Construct a returning Expr.

Source

fn select_as(&self, expr: Expr) -> Expr

Cast column expression used in select statement. It only cast database enum as text if it’s an enum column.

Source

fn select_enum_as(&self, expr: Expr) -> Expr

Cast enum column as text; do nothing if self is not an enum.

Source

fn save_as(&self, val: Expr) -> Expr

Cast value of a column into the correct type for database storage. By default, it only cast text as enum type if it’s an enum column.

Source

fn save_enum_as(&self, val: Expr) -> Expr

Cast value of an enum column as enum type; do nothing if self is not an enum.

Source

fn json_key(&self) -> &'static str

Available on crate feature with-json only.

Get the JSON key for deserialization.

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§

Source§

impl ColumnTrait for sea_orm::rbac::entity::permission::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::resource::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::role::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::role_hierarchy::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::role_permission::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::user_override::Column

Available on crate feature rbac only.
Source§

impl ColumnTrait for sea_orm::rbac::entity::user_role::Column

Available on crate feature rbac only.