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

Function transaction

tests/transaction_tests.rs:10–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8
9#[sea_orm_macros::test]
10pub 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]
50pub async fn transaction_with_reference() {

Callers

nothing calls this directly

Calls 8

unwrapMethod · 0.80
saveMethod · 0.80
filterMethod · 0.80
containsMethod · 0.80
newFunction · 0.50
create_tablesFunction · 0.50
allMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected