Skip to content

Commit 2f29543

Browse files
committed
Document update_without_returning and add rc.41 changelog entry
1 parent 85af367 commit 2f29543

5 files changed

Lines changed: 37 additions & 8 deletions

File tree

changelog/2.0.0-rc.41.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ of both `sea-orm` and `sea-orm-sync`, so default builds are unaffected.
5252
`default-features = false` builds that do not enable `stream` drop the
5353
`ouroboros` dependency and hide the streaming APIs.
5454

55+
**Update without returning** (#2965)
56+
57+
New `ActiveModelTrait::update_without_returning`, plus
58+
`UpdateOne::exec_without_returning` and `ValidatedUpdateOne::exec_without_returning`,
59+
run an UPDATE without a RETURNING clause and yield an `UpdateResult` instead of
60+
the updated model — useful on backends without RETURNING or when the updated
61+
model is not needed. Unlike `update`, it runs `before_save` but skips
62+
`after_save`, and returns `DbErr::RecordNotUpdated` when no row matches.
63+
5564
### Bug Fixes
5665

5766
**Schema-sync indexes for non-default PostgreSQL schemas** (#3085, #3084)

sea-orm-sync/src/entity/active_model.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,14 @@ pub trait ActiveModelTrait: Clone + Debug {
338338
Self::after_save(model, db, false)
339339
}
340340

341-
/// Similar to [`update`], but without returning
342-
/// It also won't execute [`ActiveModelTrait::after_save`]
341+
/// Update an ActiveModel without a RETURNING clause, yielding an
342+
/// [`UpdateResult`] instead of the updated model. Useful on backends without
343+
/// RETURNING support, or when the updated model is not needed.
344+
///
345+
/// Unlike [`ActiveModelTrait::update`], this runs
346+
/// [`ActiveModelBehavior::before_save`] but does **not** run
347+
/// [`ActiveModelBehavior::after_save`] (there is no returned model to pass to
348+
/// it). Returns [`DbErr::RecordNotUpdated`] if no row matches.
343349
fn update_without_returning<'a, C>(self, db: &'a C) -> Result<UpdateResult, DbErr>
344350
where
345351
Self: ActiveModelBehavior,

sea-orm-sync/src/executor/update.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ impl<A> ValidatedUpdateOne<A>
2323
where
2424
A: ActiveModelTrait,
2525
{
26-
/// Execute an UPDATE operation on an ActiveModel without returning the updated model
26+
/// Execute an UPDATE operation without a RETURNING clause, yielding an
27+
/// [`UpdateResult`] instead of the updated model. Returns
28+
/// [`DbErr::RecordNotUpdated`] if no row matches.
2729
pub fn exec_without_returning<C>(self, db: &C) -> Result<UpdateResult, DbErr>
2830
where
2931
C: ConnectionTrait,
@@ -48,7 +50,9 @@ impl<A> UpdateOne<A>
4850
where
4951
A: ActiveModelTrait,
5052
{
51-
/// Execute an UPDATE operation on an ActiveModel without returning the updated model
53+
/// Execute an UPDATE operation without a RETURNING clause, yielding an
54+
/// [`UpdateResult`] instead of the updated model. Returns
55+
/// [`DbErr::RecordNotUpdated`] if no row matches.
5256
pub fn exec_without_returning<C>(self, db: &C) -> Result<UpdateResult, DbErr>
5357
where
5458
C: ConnectionTrait,

src/entity/active_model.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,14 @@ pub trait ActiveModelTrait: Clone + Debug {
345345
Self::after_save(model, db, false).await
346346
}
347347

348-
/// Similar to [`update`], but without returning
349-
/// It also won't execute [`ActiveModelTrait::after_save`]
348+
/// Update an ActiveModel without a RETURNING clause, yielding an
349+
/// [`UpdateResult`] instead of the updated model. Useful on backends without
350+
/// RETURNING support, or when the updated model is not needed.
351+
///
352+
/// Unlike [`ActiveModelTrait::update`], this runs
353+
/// [`ActiveModelBehavior::before_save`] but does **not** run
354+
/// [`ActiveModelBehavior::after_save`] (there is no returned model to pass to
355+
/// it). Returns [`DbErr::RecordNotUpdated`] if no row matches.
350356
async fn update_without_returning<'a, C>(self, db: &'a C) -> Result<UpdateResult, DbErr>
351357
where
352358
Self: ActiveModelBehavior,

src/executor/update.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ impl<A> ValidatedUpdateOne<A>
2323
where
2424
A: ActiveModelTrait,
2525
{
26-
/// Execute an UPDATE operation on an ActiveModel without returning the updated model
26+
/// Execute an UPDATE operation without a RETURNING clause, yielding an
27+
/// [`UpdateResult`] instead of the updated model. Returns
28+
/// [`DbErr::RecordNotUpdated`] if no row matches.
2729
pub async fn exec_without_returning<C>(self, db: &C) -> Result<UpdateResult, DbErr>
2830
where
2931
C: ConnectionTrait,
@@ -51,7 +53,9 @@ impl<A> UpdateOne<A>
5153
where
5254
A: ActiveModelTrait,
5355
{
54-
/// Execute an UPDATE operation on an ActiveModel without returning the updated model
56+
/// Execute an UPDATE operation without a RETURNING clause, yielding an
57+
/// [`UpdateResult`] instead of the updated model. Returns
58+
/// [`DbErr::RecordNotUpdated`] if no row matches.
5559
pub async fn exec_without_returning<C>(self, db: &C) -> Result<UpdateResult, DbErr>
5660
where
5761
C: ConnectionTrait,

0 commit comments

Comments
 (0)