diff --git a/src/connector/update.rs b/src/connector/update.rs index 6ded9b13..2912c751 100644 --- a/src/connector/update.rs +++ b/src/connector/update.rs @@ -1,4 +1,6 @@ -use crate::{ActiveModelTrait, Connection, Database, ExecErr, Statement, UpdateOne}; +use crate::{ + ActiveModelTrait, Connection, Database, EntityTrait, ExecErr, Statement, UpdateMany, UpdateOne, +}; use sea_query::{QueryBuilder, UpdateStatement}; use std::future::Future; @@ -22,6 +24,19 @@ where } } +impl<'a, E> UpdateMany +where + E: EntityTrait, +{ + pub fn exec( + self, + db: &'a Database, + ) -> impl Future> + 'a { + // so that self is dropped before entering await + exec_update_only(self.query, db) + } +} + impl Updater { pub fn new(query: UpdateStatement) -> Self { Self { query } @@ -40,6 +55,10 @@ impl Updater { } } +async fn exec_update_only(query: UpdateStatement, db: &Database) -> Result { + Updater::new(query).exec(db).await +} + async fn exec_update_and_return_original( query: UpdateStatement, model: A,