diff --git a/docs-site/config.toml b/docs-site/config.toml index 385444a50..cdf66b2ed 100644 --- a/docs-site/config.toml +++ b/docs-site/config.toml @@ -71,18 +71,16 @@ name = "Models" description = 'Model your business with rich entities and avoid writing SQL, backed by SeaORM. Build relations, validation and custom logic on your entities for the best maintainability.' example = '''```rust impl Model { - pub async fn find_by_email( - db: &DatabaseConnection, - email: &str) + pub async fn find_by_email(db: &DatabaseConnection, email: &str) -> ModelResult { - Users::find().filter( - condition().eq(users::Column::Email, email).build() - ) + + Users::find() + .filter(eq(Column::Email, email)) .one(db).await? .ok_or_else(|| ModelError::EntityNotFound) } - pub async fn create_report(&self, ctx: &AppContext) -> Result<()>{ + pub async fn create_report(&self, ctx: &AppContext) -> Result<()> { ReportWorker::perform_later( &ctx, ReportArgs{ user_id: self.id } @@ -90,6 +88,8 @@ impl Model { } } + + ``` ''' diff --git a/src/model/query/dsl/mod.rs b/src/model/query/dsl/mod.rs index a66558519..998db7921 100644 --- a/src/model/query/dsl/mod.rs +++ b/src/model/query/dsl/mod.rs @@ -1,5 +1,6 @@ use sea_orm::{ sea_query::{IntoCondition, Order}, + sqlx::query, ColumnTrait, Condition, Value, }; use serde::{Deserialize, Serialize}; @@ -45,6 +46,130 @@ pub const fn with(condition: Condition) -> ConditionBuilder { ConditionBuilder { condition } } +/// See [ConditionBuilder::eq] +#[must_use] +pub fn eq>(col: T, value: V) -> ConditionBuilder { + condition().eq(col, value) +} + +/// See [ConditionBuilder::ne] +#[must_use] +pub fn not_equal>(col: T, value: V) -> ConditionBuilder { + condition().ne(col, value) +} + +/// See [ConditionBuilder::gt] +#[must_use] +pub fn gt>(col: T, value: V) -> ConditionBuilder { + condition().gt(col, value) +} + +/// See [ConditionBuilder::gte] +#[must_use] +pub fn gt_equal>(col: T, value: V) -> ConditionBuilder { + condition().gte(col, value) +} + +/// See [ConditionBuilder::lt] +#[must_use] +pub fn lt>(col: T, value: V) -> ConditionBuilder { + condition().lt(col, value) +} + +/// See [ConditionBuilder::lte] +#[must_use] +pub fn lt_equal>(col: T, value: V) -> ConditionBuilder { + condition().lte(col, value) +} + +/// See [ConditionBuilder::between] +#[must_use] +pub fn between>(col: T, a: V, b: V) -> ConditionBuilder { + condition().between(col, a, b) +} + +/// See [ConditionBuilder::not_between] +#[must_use] +pub fn not_between>(col: T, a: V, b: V) -> ConditionBuilder { + condition().not_between(col, a, b) +} + +/// See [ConditionBuilder::like] +#[must_use] +pub fn like>(col: T, a: V) -> ConditionBuilder { + condition().like(col, a) +} + +/// See [ConditionBuilder::not_like] +#[must_use] +pub fn not_like>(col: T, a: V) -> ConditionBuilder { + condition().not_like(col, a) +} + +/// See [ConditionBuilder::starts_with] +#[must_use] +pub fn starts_with>(col: T, a: V) -> ConditionBuilder { + condition().starts_with(col, a) +} + +/// See [ConditionBuilder::ends_with] +#[must_use] +pub fn ends_with>(col: T, a: V) -> ConditionBuilder { + condition().ends_with(col, a) +} + +/// See [ConditionBuilder::contains] +#[must_use] +pub fn contains>(col: T, a: V) -> ConditionBuilder { + condition().contains(col, a) +} + +/// See [ConditionBuilder::is_null] +#[must_use] +#[allow(clippy::wrong_self_convention)] +pub fn is_null(col: T) -> ConditionBuilder { + condition().is_null(col) +} + +/// See [ConditionBuilder::is_not_null] +#[must_use] +#[allow(clippy::wrong_self_convention)] +pub fn is_not_null(col: T) -> ConditionBuilder { + condition().is_not_null(col) +} + +/// See [ConditionBuilder::is_in] +#[must_use] +#[allow(clippy::wrong_self_convention)] +pub fn is_in, I: IntoIterator>( + col: T, + values: I, +) -> ConditionBuilder { + condition().is_in(col, values) +} + +/// See [ConditionBuilder::is_not_in] +#[must_use] +#[allow(clippy::wrong_self_convention)] +pub fn is_not_in, I: IntoIterator>( + col: T, + values: I, +) -> ConditionBuilder { + condition().is_not_in(col, values) +} + +/// See [ConditionBuilder::date_range] +#[must_use] +pub fn date_range(col: T) -> date_range::DateRangeBuilder { + date_range::DateRangeBuilder::new(condition(), col) +} + +impl IntoCondition for ConditionBuilder { + fn into_condition(self) -> Condition { + self.build() + } +} + /// Builder query condition /// /// # Examples