Skip to main content

sea_query/query/
update.rs

1use std::borrow::Cow;
2
3use crate::{
4    ConditionHolder, ConditionalStatement, DynIden, Expr, IntoColumnRef, IntoCondition, IntoIden,
5    IntoTableRef, LogicalChainOper, NullOrdering, Order, OrderExpr, OrderedStatement, QueryBuilder,
6    QueryStatement, QueryStatementBuilder, QueryStatementWriter, ReturningClause, SqlWriter,
7    SubQueryStatement, TableRef, Value, Values, WithClause, WithQuery,
8};
9
10/// Update existing rows in the table
11///
12/// # Examples
13///
14/// ```
15/// use sea_query::{tests_cfg::*, *};
16///
17/// let query = Query::update()
18///     .table(Glyph::Table)
19///     .values([(Glyph::Aspect, 1.23.into()), (Glyph::Image, "123".into())])
20///     .and_where(Expr::col(Glyph::Id).eq(1))
21///     .to_owned();
22///
23/// assert_eq!(
24///     query.to_string(MysqlQueryBuilder),
25///     r#"UPDATE `glyph` SET `aspect` = 1.23, `image` = '123' WHERE `id` = 1"#
26/// );
27/// assert_eq!(
28///     query.to_string(PostgresQueryBuilder),
29///     r#"UPDATE "glyph" SET "aspect" = 1.23, "image" = '123' WHERE "id" = 1"#
30/// );
31/// assert_eq!(
32///     query.to_string(SqliteQueryBuilder),
33///     r#"UPDATE "glyph" SET "aspect" = 1.23, "image" = '123' WHERE "id" = 1"#
34/// );
35/// ```
36#[derive(Default, Debug, Clone, PartialEq)]
37pub struct UpdateStatement {
38    pub(crate) table: Option<Box<TableRef>>,
39    pub(crate) from: Vec<TableRef>,
40    pub(crate) values: Vec<(DynIden, Box<Expr>)>,
41    pub(crate) r#where: ConditionHolder,
42    pub(crate) orders: Vec<OrderExpr>,
43    pub(crate) limit: Option<Value>,
44    pub(crate) returning: Option<ReturningClause>,
45    pub(crate) with: Option<WithClause>,
46}
47
48impl UpdateStatement {
49    /// Construct a new [`UpdateStatement`]
50    pub fn new() -> Self {
51        Self::default()
52    }
53
54    pub fn take(&mut self) -> Self {
55        Self {
56            table: self.table.take(),
57            from: std::mem::take(&mut self.from),
58            values: std::mem::take(&mut self.values),
59            r#where: std::mem::take(&mut self.r#where),
60            orders: std::mem::take(&mut self.orders),
61            limit: self.limit.take(),
62            returning: self.returning.take(),
63            with: self.with.take(),
64        }
65    }
66
67    /// Specify which table to update.
68    ///
69    /// # Examples
70    ///
71    /// See [`UpdateStatement::values`]
72    #[allow(clippy::wrong_self_convention)]
73    pub fn table<T>(&mut self, tbl_ref: T) -> &mut Self
74    where
75        T: IntoTableRef,
76    {
77        self.table = Some(Box::new(tbl_ref.into_table_ref()));
78        self
79    }
80
81    /// Update using data from another table (`UPDATE .. FROM ..`).
82    ///
83    /// # MySQL Notes
84    ///
85    /// MySQL doesn't support the UPDATE FROM syntax. And the current implementation attempt to tranform it to the UPDATE JOIN syntax,
86    /// which only works for one join target.
87    ///
88    /// # Examples
89    ///
90    /// ```
91    /// use sea_query::{audit::*, tests_cfg::*, *};
92    ///
93    /// let query = Query::update()
94    ///     .table(Glyph::Table)
95    ///     .value(Glyph::Tokens, Expr::column((Char::Table, Char::Character)))
96    ///     .from(Char::Table)
97    ///     .cond_where(
98    ///         Expr::col((Glyph::Table, Glyph::Image))
99    ///             .eq(Expr::col((Char::Table, Char::UserData))),
100    ///     )
101    ///     .to_owned();
102    ///
103    /// assert_eq!(
104    ///     query.to_string(MysqlQueryBuilder),
105    ///     "UPDATE `glyph` JOIN `character` ON `glyph`.`image` = `character`.`user_data` SET `glyph`.`tokens` = `character`.`character`"
106    /// );
107    /// assert_eq!(
108    ///     query.to_string(PostgresQueryBuilder),
109    ///     r#"UPDATE "glyph" SET "tokens" = "character"."character" FROM "character" WHERE "glyph"."image" = "character"."user_data""#
110    /// );
111    /// assert_eq!(
112    ///     query.to_string(SqliteQueryBuilder),
113    ///     r#"UPDATE "glyph" SET "tokens" = "character"."character" FROM "character" WHERE "glyph"."image" = "character"."user_data""#
114    /// );
115    /// assert_eq!(
116    ///     query.audit().unwrap().updated_tables(),
117    ///     [Glyph::Table.into_iden()]
118    /// );
119    /// assert_eq!(
120    ///     query.audit().unwrap().selected_tables(),
121    ///     [Char::Table.into_iden()]
122    /// );
123    /// ```
124    pub fn from<R>(&mut self, tbl_ref: R) -> &mut Self
125    where
126        R: IntoTableRef,
127    {
128        self.from_from(tbl_ref.into_table_ref())
129    }
130
131    #[allow(clippy::wrong_self_convention)]
132    fn from_from(&mut self, select: TableRef) -> &mut Self {
133        self.from.push(select);
134        self
135    }
136
137    /// Update column values. To set multiple column-value pairs at once.
138    ///
139    /// # Examples
140    ///
141    /// ```
142    /// use sea_query::{audit::*, tests_cfg::*, *};
143    ///
144    /// let query = Query::update()
145    ///     .table(Glyph::Table)
146    ///     .values([
147    ///         (Glyph::Aspect, 2.1345.into()),
148    ///         (Glyph::Image, "235m".into()),
149    ///     ])
150    ///     .to_owned();
151    ///
152    /// assert_eq!(
153    ///     query.to_string(MysqlQueryBuilder),
154    ///     r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
155    /// );
156    /// assert_eq!(
157    ///     query.to_string(PostgresQueryBuilder),
158    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m'"#
159    /// );
160    /// assert_eq!(
161    ///     query.to_string(SqliteQueryBuilder),
162    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m'"#
163    /// );
164    /// assert_eq!(
165    ///     query.audit().unwrap().updated_tables(),
166    ///     [Glyph::Table.into_iden()]
167    /// );
168    /// assert_eq!(query.audit().unwrap().selected_tables(), []);
169    /// ```
170    pub fn values<T, I>(&mut self, values: I) -> &mut Self
171    where
172        T: IntoIden,
173        I: IntoIterator<Item = (T, Expr)>,
174    {
175        for (k, v) in values.into_iter() {
176            self.values.push((k.into_iden(), Box::new(v)));
177        }
178        self
179    }
180
181    /// Update column value by [`Expr`].
182    ///
183    /// # Examples
184    ///
185    /// ```
186    /// use sea_query::{*, tests_cfg::*};
187    ///
188    /// let query = Query::update()
189    ///     .table(Glyph::Table)
190    ///     .value(Glyph::Aspect, Expr::cust("60 * 24 * 24"))
191    ///     .values([
192    ///         (Glyph::Image, "24B0E11951B03B07F8300FD003983F03F0780060".into()),
193    ///     ])
194    ///     .to_owned();
195    ///
196    /// assert_eq!(
197    ///     query.to_string(MysqlQueryBuilder),
198    ///     r#"UPDATE `glyph` SET `aspect` = 60 * 24 * 24, `image` = '24B0E11951B03B07F8300FD003983F03F0780060'"#
199    /// );
200    /// assert_eq!(
201    ///     query.to_string(PostgresQueryBuilder),
202    ///     r#"UPDATE "glyph" SET "aspect" = 60 * 24 * 24, "image" = '24B0E11951B03B07F8300FD003983F03F0780060'"#
203    /// );
204    /// assert_eq!(
205    ///     query.to_string(SqliteQueryBuilder),
206    ///     r#"UPDATE "glyph" SET "aspect" = 60 * 24 * 24, "image" = '24B0E11951B03B07F8300FD003983F03F0780060'"#
207    /// );
208    ///
209    /// let query = Query::update()
210    ///     .table(Glyph::Table)
211    ///     .value(Glyph::Aspect, Expr::value(Value::Int(None)))
212    ///     .to_owned();
213    ///
214    /// assert_eq!(
215    ///     query.to_string(MysqlQueryBuilder),
216    ///     r#"UPDATE `glyph` SET `aspect` = NULL"#
217    /// );
218    /// assert_eq!(
219    ///     query.to_string(PostgresQueryBuilder),
220    ///     r#"UPDATE "glyph" SET "aspect" = NULL"#
221    /// );
222    /// assert_eq!(
223    ///     query.to_string(SqliteQueryBuilder),
224    ///     r#"UPDATE "glyph" SET "aspect" = NULL"#
225    /// );
226    /// ```
227    pub fn value<C, T>(&mut self, col: C, value: T) -> &mut Self
228    where
229        C: IntoIden,
230        T: Into<Expr>,
231    {
232        self.values.push((col.into_iden(), Box::new(value.into())));
233        self
234    }
235
236    /// Limit number of updated rows.
237    pub fn limit(&mut self, limit: u64) -> &mut Self {
238        self.limit = Some(limit.into());
239        self
240    }
241
242    /// RETURNING expressions.
243    ///
244    /// # Examples
245    ///
246    /// ```
247    /// use sea_query::{audit::*, tests_cfg::*, *};
248    ///
249    /// let query = Query::update()
250    ///     .table(Glyph::Table)
251    ///     .value(Glyph::Aspect, 2.1345)
252    ///     .value(Glyph::Image, "235m")
253    ///     .returning(Query::returning().columns([Glyph::Id]))
254    ///     .to_owned();
255    ///
256    /// assert_eq!(
257    ///     query.to_string(MysqlQueryBuilder),
258    ///     r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
259    /// );
260    /// assert_eq!(
261    ///     query.to_string(PostgresQueryBuilder),
262    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
263    /// );
264    /// assert_eq!(
265    ///     query.to_string(SqliteQueryBuilder),
266    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
267    /// );
268    /// assert_eq!(
269    ///     query.audit().unwrap().updated_tables(),
270    ///     [Glyph::Table.into_iden()]
271    /// );
272    /// assert_eq!(
273    ///     query.audit().unwrap().selected_tables(),
274    ///     [Glyph::Table.into_iden()]
275    /// );
276    /// ```
277    pub fn returning(&mut self, returning: ReturningClause) -> &mut Self {
278        self.returning = Some(returning);
279        self
280    }
281
282    /// RETURNING expressions for a column.
283    ///
284    /// # Examples
285    ///
286    /// ```
287    /// use sea_query::{tests_cfg::*, *};
288    ///
289    /// let query = Query::update()
290    ///     .table(Glyph::Table)
291    ///     .table(Glyph::Table)
292    ///     .value(Glyph::Aspect, 2.1345)
293    ///     .value(Glyph::Image, "235m")
294    ///     .returning_col(Glyph::Id)
295    ///     .to_owned();
296    ///
297    /// assert_eq!(
298    ///     query.to_string(MysqlQueryBuilder),
299    ///     r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
300    /// );
301    /// assert_eq!(
302    ///     query.to_string(PostgresQueryBuilder),
303    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
304    /// );
305    /// assert_eq!(
306    ///     query.to_string(SqliteQueryBuilder),
307    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING "id""#
308    /// );
309    /// ```
310    pub fn returning_col<C>(&mut self, col: C) -> &mut Self
311    where
312        C: IntoColumnRef,
313    {
314        self.returning(ReturningClause::Columns(vec![col.into_column_ref()]))
315    }
316
317    /// RETURNING expressions all columns.
318    ///
319    /// # Examples
320    ///
321    /// ```
322    /// use sea_query::{tests_cfg::*, *};
323    ///
324    /// let query = Query::update()
325    ///     .table(Glyph::Table)
326    ///     .table(Glyph::Table)
327    ///     .value(Glyph::Aspect, 2.1345)
328    ///     .value(Glyph::Image, "235m")
329    ///     .returning_all()
330    ///     .to_owned();
331    ///
332    /// assert_eq!(
333    ///     query.to_string(MysqlQueryBuilder),
334    ///     r#"UPDATE `glyph` SET `aspect` = 2.1345, `image` = '235m'"#
335    /// );
336    /// assert_eq!(
337    ///     query.to_string(PostgresQueryBuilder),
338    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING *"#
339    /// );
340    /// assert_eq!(
341    ///     query.to_string(SqliteQueryBuilder),
342    ///     r#"UPDATE "glyph" SET "aspect" = 2.1345, "image" = '235m' RETURNING *"#
343    /// );
344    /// ```
345    pub fn returning_all(&mut self) -> &mut Self {
346        self.returning(ReturningClause::All)
347    }
348
349    /// Create a [WithQuery] by specifying a [WithClause] to execute this query with.
350    ///
351    /// # Examples
352    ///
353    /// ```
354    /// use sea_query::{IntoCondition, IntoIden, audit::*, tests_cfg::*, *};
355    ///
356    /// let select = SelectStatement::new()
357    ///         .columns([Glyph::Id])
358    ///         .from(Glyph::Table)
359    ///         .and_where(Expr::col(Glyph::Image).like("0%"))
360    ///         .to_owned();
361    ///     let cte = CommonTableExpression::new()
362    ///         .query(select)
363    ///         .column(Glyph::Id)
364    ///         .table_name("cte")
365    ///         .to_owned();
366    ///     let with_clause = WithClause::new().cte(cte).to_owned();
367    ///     let update = UpdateStatement::new()
368    ///         .table(Glyph::Table)
369    ///         .and_where(Expr::col(Glyph::Id).in_subquery(SelectStatement::new().column(Glyph::Id).from("cte").to_owned()))
370    ///         .value(Glyph::Aspect, Expr::cust("60 * 24 * 24"))
371    ///         .to_owned();
372    ///     let query = update.with(with_clause);
373    ///
374    /// assert_eq!(
375    ///     query.to_string(MysqlQueryBuilder),
376    ///     r#"WITH `cte` (`id`) AS (SELECT `id` FROM `glyph` WHERE `image` LIKE '0%') UPDATE `glyph` SET `aspect` = 60 * 24 * 24 WHERE `id` IN (SELECT `id` FROM `cte`)"#
377    /// );
378    /// assert_eq!(
379    ///     query.to_string(PostgresQueryBuilder),
380    ///     r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
381    /// );
382    /// assert_eq!(
383    ///     query.to_string(SqliteQueryBuilder),
384    ///     r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
385    /// );
386    /// assert_eq!(
387    ///     query.audit_unwrap().updated_tables(),
388    ///     [Glyph::Table.into_iden()]
389    /// );
390    /// assert_eq!(
391    ///     query.audit_unwrap().selected_tables(),
392    ///     [Glyph::Table.into_iden()]
393    /// );
394    /// ```
395    pub fn with(self, clause: WithClause) -> WithQuery {
396        clause.query(self)
397    }
398
399    /// Create a Common Table Expression by specifying a [CommonTableExpression][crate::CommonTableExpression]
400    /// or [WithClause] to execute this query with.
401    ///
402    /// # Examples
403    ///
404    /// ```
405    /// use sea_query::{IntoCondition, IntoIden, audit::*, tests_cfg::*, *};
406    ///
407    /// let select = SelectStatement::new()
408    ///         .columns([Glyph::Id])
409    ///         .from(Glyph::Table)
410    ///         .and_where(Expr::col(Glyph::Image).like("0%"))
411    ///         .to_owned();
412    ///     let cte = CommonTableExpression::new()
413    ///         .query(select)
414    ///         .column(Glyph::Id)
415    ///         .table_name("cte")
416    ///         .to_owned();
417    ///     let with_clause = WithClause::new().cte(cte).to_owned();
418    ///     let query = UpdateStatement::new()
419    ///         .table(Glyph::Table)
420    ///         .and_where(Expr::col(Glyph::Id).in_subquery(SelectStatement::new().column(Glyph::Id).from("cte").to_owned()))
421    ///         .value(Glyph::Aspect, Expr::cust("60 * 24 * 24"))
422    ///         .with_cte(with_clause)
423    ///         .to_owned();
424    ///
425    /// assert_eq!(
426    ///     query.to_string(MysqlQueryBuilder),
427    ///     r#"WITH `cte` (`id`) AS (SELECT `id` FROM `glyph` WHERE `image` LIKE '0%') UPDATE `glyph` SET `aspect` = 60 * 24 * 24 WHERE `id` IN (SELECT `id` FROM `cte`)"#
428    /// );
429    /// assert_eq!(
430    ///     query.to_string(PostgresQueryBuilder),
431    ///     r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
432    /// );
433    /// assert_eq!(
434    ///     query.to_string(SqliteQueryBuilder),
435    ///     r#"WITH "cte" ("id") AS (SELECT "id" FROM "glyph" WHERE "image" LIKE '0%') UPDATE "glyph" SET "aspect" = 60 * 24 * 24 WHERE "id" IN (SELECT "id" FROM "cte")"#
436    /// );
437    /// assert_eq!(
438    ///     query.audit_unwrap().updated_tables(),
439    ///     [Glyph::Table.into_iden()]
440    /// );
441    /// assert_eq!(
442    ///     query.audit_unwrap().selected_tables(),
443    ///     [Glyph::Table.into_iden()]
444    /// );
445    /// ```
446    pub fn with_cte<C: Into<WithClause>>(&mut self, clause: C) -> &mut Self {
447        self.with = Some(clause.into());
448        self
449    }
450
451    /// Get column values
452    pub fn get_values(&self) -> &[(DynIden, Box<Expr>)] {
453        &self.values
454    }
455}
456
457impl QueryStatementBuilder for UpdateStatement {
458    fn build_collect_any_into(&self, query_builder: &impl QueryBuilder, sql: &mut impl SqlWriter) {
459        query_builder.prepare_update_statement(self, sql);
460    }
461}
462
463impl UpdateStatement {
464    pub fn build_any(&self, query_builder: &impl QueryBuilder) -> (String, Values) {
465        <Self as QueryStatementBuilder>::build_any(self, query_builder)
466    }
467
468    pub fn build_collect_any(
469        &self,
470        query_builder: &impl QueryBuilder,
471        sql: &mut impl SqlWriter,
472    ) -> String {
473        <Self as QueryStatementBuilder>::build_collect_any(self, query_builder, sql)
474    }
475
476    pub fn build_collect_any_into(
477        &self,
478        query_builder: &impl QueryBuilder,
479        sql: &mut impl SqlWriter,
480    ) {
481        <Self as QueryStatementBuilder>::build_collect_any_into(self, query_builder, sql)
482    }
483}
484
485impl From<UpdateStatement> for QueryStatement {
486    fn from(s: UpdateStatement) -> Self {
487        Self::Update(s)
488    }
489}
490
491impl From<UpdateStatement> for SubQueryStatement {
492    fn from(s: UpdateStatement) -> Self {
493        Self::UpdateStatement(s)
494    }
495}
496
497impl QueryStatementWriter for UpdateStatement {
498    fn build_collect_into<T: QueryBuilder>(&self, query_builder: T, sql: &mut impl SqlWriter) {
499        query_builder.prepare_update_statement(self, sql);
500    }
501}
502
503impl UpdateStatement {
504    pub fn to_string<T: QueryBuilder>(&self, query_builder: T) -> String {
505        <Self as QueryStatementWriter>::to_string(self, query_builder)
506    }
507
508    pub fn build<T: QueryBuilder>(&self, query_builder: T) -> (String, Values) {
509        <Self as QueryStatementWriter>::build(self, query_builder)
510    }
511
512    pub fn build_collect<T: QueryBuilder>(
513        &self,
514        query_builder: T,
515        sql: &mut impl SqlWriter,
516    ) -> String {
517        <Self as QueryStatementWriter>::build_collect(self, query_builder, sql)
518    }
519
520    pub fn build_collect_into<T: QueryBuilder>(&self, query_builder: T, sql: &mut impl SqlWriter) {
521        <Self as QueryStatementWriter>::build_collect_into(self, query_builder, sql);
522    }
523}
524
525impl OrderedStatement for UpdateStatement {
526    fn add_order_by(&mut self, order: OrderExpr) -> &mut Self {
527        self.orders.push(order);
528        self
529    }
530
531    fn clear_order_by(&mut self) -> &mut Self {
532        self.orders = Vec::new();
533        self
534    }
535}
536
537impl UpdateStatement {
538    pub fn add_order_by(&mut self, order: OrderExpr) -> &mut Self {
539        <Self as OrderedStatement>::add_order_by(self, order)
540    }
541
542    pub fn clear_order_by(&mut self) -> &mut Self {
543        <Self as OrderedStatement>::clear_order_by(self)
544    }
545
546    pub fn order_by<T: IntoColumnRef>(&mut self, col: T, order: Order) -> &mut Self {
547        <Self as OrderedStatement>::order_by(self, col, order)
548    }
549
550    pub fn order_by_expr(&mut self, expr: Expr, order: Order) -> &mut Self {
551        <Self as OrderedStatement>::order_by_expr(self, expr, order)
552    }
553
554    pub fn order_by_customs<I, T>(&mut self, cols: I) -> &mut Self
555    where
556        T: Into<Cow<'static, str>>,
557        I: IntoIterator<Item = (T, Order)>,
558    {
559        <Self as OrderedStatement>::order_by_customs(self, cols)
560    }
561
562    pub fn order_by_columns<I, T>(&mut self, cols: I) -> &mut Self
563    where
564        T: IntoColumnRef,
565        I: IntoIterator<Item = (T, Order)>,
566    {
567        <Self as OrderedStatement>::order_by_columns(self, cols)
568    }
569
570    pub fn order_by_with_nulls<T: IntoColumnRef>(
571        &mut self,
572        col: T,
573        order: Order,
574        nulls: NullOrdering,
575    ) -> &mut Self {
576        <Self as OrderedStatement>::order_by_with_nulls(self, col, order, nulls)
577    }
578
579    pub fn order_by_expr_with_nulls(
580        &mut self,
581        expr: Expr,
582        order: Order,
583        nulls: NullOrdering,
584    ) -> &mut Self {
585        <Self as OrderedStatement>::order_by_expr_with_nulls(self, expr, order, nulls)
586    }
587
588    pub fn order_by_customs_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
589    where
590        T: Into<Cow<'static, str>>,
591        I: IntoIterator<Item = (T, Order, NullOrdering)>,
592    {
593        <Self as OrderedStatement>::order_by_customs_with_nulls(self, cols)
594    }
595
596    pub fn order_by_columns_with_nulls<I, T>(&mut self, cols: I) -> &mut Self
597    where
598        T: IntoColumnRef,
599        I: IntoIterator<Item = (T, Order, NullOrdering)>,
600    {
601        <Self as OrderedStatement>::order_by_columns_with_nulls(self, cols)
602    }
603}
604
605impl ConditionalStatement for UpdateStatement {
606    fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self {
607        self.r#where.add_and_or(condition);
608        self
609    }
610
611    fn cond_where<C>(&mut self, condition: C) -> &mut Self
612    where
613        C: IntoCondition,
614    {
615        self.r#where.add_condition(condition.into_condition());
616        self
617    }
618}
619
620impl UpdateStatement {
621    pub fn and_where(&mut self, other: Expr) -> &mut Self {
622        <Self as ConditionalStatement>::and_where(self, other)
623    }
624
625    pub fn and_where_option(&mut self, other: Option<Expr>) -> &mut Self {
626        <Self as ConditionalStatement>::and_where_option(self, other)
627    }
628
629    pub fn and_or_where(&mut self, condition: LogicalChainOper) -> &mut Self {
630        <Self as ConditionalStatement>::and_or_where(self, condition)
631    }
632
633    pub fn cond_where<C: IntoCondition>(&mut self, condition: C) -> &mut Self {
634        <Self as ConditionalStatement>::cond_where(self, condition)
635    }
636}