diff --git a/SeaORM/docs/08-advanced-query/01-custom-select.md b/SeaORM/docs/08-advanced-query/01-custom-select.md index 15ff2db8449..409ea7f18dc 100644 --- a/SeaORM/docs/08-advanced-query/01-custom-select.md +++ b/SeaORM/docs/08-advanced-query/01-custom-select.md @@ -142,3 +142,23 @@ let res: Vec<(String, i64)> = cake::Entity::find() .all(&db) .await?; ``` + +## Appling an Operation if Value Exists + +Apply an operation on the [QueryTrait::QueryStatement](https://docs.rs/sea-orm/*/sea_orm/query/trait.QueryTrait.html#associatedtype.QueryStatement) if the given `Option` is `Some(_)`. + +```rust +use sea_orm::{entity::*, query::*, tests_cfg::cake, DbBackend}; + +assert_eq!( + cake::Entity::find() + .apply_if(Some(3), |mut query, v| { + query.filter(cake::Column::Id.eq(v)) + }) + .apply_if(Some(100), QuerySelect::limit) + .apply_if(None, QuerySelect::offset::>) // no-op + .build(DbBackend::Postgres) + .to_string(), + r#"SELECT "cake"."id", "cake"."name" FROM "cake" WHERE "cake"."id" = 3 LIMIT 100"# +); +```