Doc tests

This commit is contained in:
Chris Tsang 2021-06-10 02:07:26 +08:00
parent c70c941712
commit e6309c54b3

View File

@ -27,6 +27,21 @@ where
} }
impl Update { impl Update {
/// Update one ActiveModel
///
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::cake, sea_query::PostgresQueryBuilder};
///
/// assert_eq!(
/// Update::one(cake::ActiveModel {
/// id: ActiveValue::set(1),
/// name: ActiveValue::set("Apple Pie".to_owned()),
/// })
/// .build(PostgresQueryBuilder)
/// .to_string(),
/// r#"UPDATE "cake" SET "name" = 'Apple Pie' WHERE "cake"."id" = 1"#,
/// );
/// ```
pub fn one<E, A>(model: A) -> UpdateOne<A> pub fn one<E, A>(model: A) -> UpdateOne<A>
where where
E: EntityTrait, E: EntityTrait,
@ -41,6 +56,20 @@ impl Update {
myself.prepare() myself.prepare()
} }
/// Update many ActiveModel
///
/// ```
/// use sea_orm::{entity::*, query::*, tests_cfg::fruit, sea_query::{Expr, PostgresQueryBuilder}};
///
/// assert_eq!(
/// Update::many(fruit::Entity)
/// .col_expr(fruit::Column::Name, Expr::value("Golden Apple"))
/// .filter(fruit::Column::Name.contains("Apple"))
/// .build(PostgresQueryBuilder)
/// .to_string(),
/// r#"UPDATE "fruit" SET "name" = 'Golden Apple' WHERE "fruit"."name" LIKE '%Apple%'"#,
/// );
/// ```
pub fn many<E>(entity: E) -> UpdateMany<E> pub fn many<E>(entity: E) -> UpdateMany<E>
where where
E: EntityTrait, E: EntityTrait,
@ -204,10 +233,10 @@ mod tests {
assert_eq!( assert_eq!(
Update::many(fruit::Entity) Update::many(fruit::Entity)
.col_expr(fruit::Column::CakeId, Expr::value(Value::Null)) .col_expr(fruit::Column::CakeId, Expr::value(Value::Null))
.filter(fruit::Column::Name.contains("Apple")) .filter(fruit::Column::Id.eq(2))
.build(PostgresQueryBuilder) .build(PostgresQueryBuilder)
.to_string(), .to_string(),
r#"UPDATE "fruit" SET "cake_id" = NULL WHERE "fruit"."name" LIKE '%Apple%'"#, r#"UPDATE "fruit" SET "cake_id" = NULL WHERE "fruit"."id" = 2"#,
); );
} }
} }