| 8 | |
| 9 | #[sea_orm_macros::test] |
| 10 | pub async fn transaction() { |
| 11 | let ctx = TestContext::new("transaction_test").await; |
| 12 | create_tables(&ctx.db).await.unwrap(); |
| 13 | |
| 14 | ctx.db |
| 15 | .transaction::<_, _, DbErr>(|txn| { |
| 16 | Box::pin(async move { |
| 17 | let _ = bakery::ActiveModel { |
| 18 | name: Set("SeaSide Bakery".to_owned()), |
| 19 | profit_margin: Set(10.4), |
| 20 | ..Default::default() |
| 21 | } |
| 22 | .save(txn) |
| 23 | .await?; |
| 24 | |
| 25 | let _ = bakery::ActiveModel { |
| 26 | name: Set("Top Bakery".to_owned()), |
| 27 | profit_margin: Set(15.0), |
| 28 | ..Default::default() |
| 29 | } |
| 30 | .save(txn) |
| 31 | .await?; |
| 32 | |
| 33 | let bakeries = Bakery::find() |
| 34 | .filter(bakery::Column::Name.contains("Bakery")) |
| 35 | .all(txn) |
| 36 | .await?; |
| 37 | |
| 38 | assert_eq!(bakeries.len(), 2); |
| 39 | |
| 40 | Ok(()) |
| 41 | }) |
| 42 | }) |
| 43 | .await |
| 44 | .unwrap(); |
| 45 | |
| 46 | ctx.delete().await; |
| 47 | } |
| 48 | |
| 49 | #[sea_orm_macros::test] |
| 50 | pub async fn transaction_with_reference() { |