pub trait ColumnTrait:
IdenStatic
+ IntoEnumIterator
+ FromStr {
type EntityName: EntityName;
Show 38 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 in_subquery(&self, s: SelectStatement) -> Expr { ... }
fn not_in_subquery(&self, s: SelectStatement) -> Expr { ... }
fn into_expr(self) -> Expr { ... }
fn into_returning_expr(self, db_backend: DatabaseBackend) -> 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
Operations and comparisons available on every entity column.
Implemented by the generated Column enum for each entity, this is what
turns entity::COLUMN.field.eq(42) into a filter expression. Most methods
(eq, lt, like, is_in, …) mirror their counterparts on
sea_query::Expr but qualify the column with its table automatically.
Required Associated Types§
Sourcetype EntityName: EntityName
type EntityName: EntityName
The entity this column belongs to.
Required Methods§
Provided Methods§
Sourcefn enum_type_name(&self) -> Option<&'static str>
fn enum_type_name(&self) -> Option<&'static str>
If the column maps to a database ENUM, the enum’s type name.
Returns None for non-enum columns.
Sourcefn entity_name(&self) -> DynIden
fn entity_name(&self) -> DynIden
Table iden of the entity this column belongs to.
Sourcefn as_column_ref(&self) -> (DynIden, DynIden)
fn as_column_ref(&self) -> (DynIden, DynIden)
Fully-qualified (table, column) reference, used when building
expressions that need to disambiguate columns across joined tables.
Sourcefn eq<V>(&self, v: V) -> Expr
fn eq<V>(&self, v: V) -> Expr
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"
);Sourcefn ne<V>(&self, v: V) -> Expr
fn ne<V>(&self, v: V) -> Expr
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"
);fn gt<V>(&self, v: V) -> Expr
fn gte<V>(&self, v: V) -> Expr
fn lt<V>(&self, v: V) -> Expr
fn lte<V>(&self, v: V) -> Expr
Sourcefn between<V>(&self, a: V, b: V) -> Expr
fn between<V>(&self, a: V, b: V) -> Expr
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"
);Sourcefn not_between<V>(&self, a: V, b: V) -> Expr
fn not_between<V>(&self, a: V, b: V) -> Expr
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"
);Sourcefn like<T>(&self, s: T) -> Exprwhere
T: IntoLikeExpr,
fn like<T>(&self, s: T) -> Exprwhere
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'"
);Sourcefn not_like<T>(&self, s: T) -> Exprwhere
T: IntoLikeExpr,
fn not_like<T>(&self, s: T) -> Exprwhere
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'"
);Sourcefn ilike<T>(&self, s: T) -> Exprwhere
T: IntoLikeExpr,
fn ilike<T>(&self, s: T) -> Exprwhere
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'"#
);Sourcefn not_ilike<T>(&self, s: T) -> Exprwhere
T: IntoLikeExpr,
fn not_ilike<T>(&self, s: T) -> Exprwhere
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'"#
);Sourcefn starts_with<T>(&self, s: T) -> Expr
fn starts_with<T>(&self, s: T) -> Expr
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%'"
);Sourcefn ends_with<T>(&self, s: T) -> Expr
fn ends_with<T>(&self, s: T) -> Expr
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'"
);Sourcefn contains<T>(&self, s: T) -> Expr
fn contains<T>(&self, s: T) -> Expr
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%'"
);Sourcefn is_not_null(&self) -> Expr
fn is_not_null(&self) -> Expr
See also SeaQuery’s method with same name.
Sourcefn if_null<V>(&self, v: V) -> Expr
fn if_null<V>(&self, v: V) -> Expr
Provide fallback value if the column is null (null coalescing)
fn is_in<V, I>(&self, v: I) -> Expr
fn is_not_in<V, I>(&self, v: I) -> Expr
fn in_subquery(&self, s: SelectStatement) -> Expr
fn not_in_subquery(&self, s: SelectStatement) -> Expr
Sourcefn into_expr(self) -> Expr
fn into_expr(self) -> Expr
Wrap the column in a plain Expr, suitable for use anywhere a
sea_query expression is expected.
Sourcefn into_returning_expr(self, db_backend: DatabaseBackend) -> Expr
fn into_returning_expr(self, db_backend: DatabaseBackend) -> Expr
Wrap the column as the expression used inside a RETURNING clause
for the given backend.
Sourcefn select_as(&self, expr: Expr) -> Expr
fn select_as(&self, expr: Expr) -> Expr
Apply the standard SELECT-side cast for this column. By default, enum columns are cast to text; non-enum columns are returned as-is.
Sourcefn select_enum_as(&self, expr: Expr) -> Expr
fn select_enum_as(&self, expr: Expr) -> Expr
Cast an enum column to text; no-op for non-enum columns.
Sourcefn save_as(&self, val: Expr) -> Expr
fn save_as(&self, val: Expr) -> Expr
Apply the standard write-side cast: convert text into the database’s enum type for enum columns, return as-is otherwise.
Sourcefn save_enum_as(&self, val: Expr) -> Expr
fn save_enum_as(&self, val: Expr) -> Expr
Cast a value into the column’s enum type; no-op for non-enum columns.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".