MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / transaction_begin_rollback

Function transaction_begin_rollback

tests/transaction_tests.rs:181–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

179
180#[sea_orm_macros::test]
181pub async fn transaction_begin_rollback() -> Result<(), DbErr> {
182 let ctx = TestContext::new("transaction_begin_rollback_test").await;
183 create_tables(&ctx.db).await?;
184
185 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0);
186
187 {
188 // Transaction begin in this scope
189 let txn = ctx.db.begin().await?;
190
191 bakery::ActiveModel {
192 name: Set("SeaSide Bakery".to_owned()),
193 profit_margin: Set(10.4),
194 ..Default::default()
195 }
196 .save(&txn)
197 .await?;
198
199 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 1);
200
201 bakery::ActiveModel {
202 name: Set("Top Bakery".to_owned()),
203 profit_margin: Set(15.0),
204 ..Default::default()
205 }
206 .save(&txn)
207 .await?;
208
209 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 2);
210
211 // Rollback changes before the end of scope
212 txn.rollback().await?;
213 }
214
215 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0);
216
217 ctx.delete().await;
218 Ok(())
219}
220
221#[sea_orm_macros::test]
222pub async fn transaction_closure_commit() -> Result<(), DbErr> {

Callers

nothing calls this directly

Calls 6

saveMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
beginMethod · 0.45
rollbackMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected