()
| 98 | |
| 99 | #[sea_orm_macros::test] |
| 100 | pub async fn transaction_begin_out_of_scope() -> Result<(), DbErr> { |
| 101 | let ctx = TestContext::new("transaction_begin_out_of_scope_test").await; |
| 102 | create_tables(&ctx.db).await?; |
| 103 | |
| 104 | assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0); |
| 105 | |
| 106 | { |
| 107 | // Transaction begin in this scope |
| 108 | let txn = ctx.db.begin().await?; |
| 109 | |
| 110 | bakery::ActiveModel { |
| 111 | name: Set("SeaSide Bakery".to_owned()), |
| 112 | profit_margin: Set(10.4), |
| 113 | ..Default::default() |
| 114 | } |
| 115 | .save(&txn) |
| 116 | .await?; |
| 117 | |
| 118 | assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 1); |
| 119 | |
| 120 | bakery::ActiveModel { |
| 121 | name: Set("Top Bakery".to_owned()), |
| 122 | profit_margin: Set(15.0), |
| 123 | ..Default::default() |
| 124 | } |
| 125 | .save(&txn) |
| 126 | .await?; |
| 127 | |
| 128 | assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 2); |
| 129 | |
| 130 | // The scope ended and transaction is dropped without commit |
| 131 | } |
| 132 | |
| 133 | assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0); |
| 134 | |
| 135 | ctx.delete().await; |
| 136 | Ok(()) |
| 137 | } |
| 138 | |
| 139 | #[sea_orm_macros::test] |
| 140 | pub async fn transaction_begin_commit() -> Result<(), DbErr> { |
nothing calls this directly
no test coverage detected