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

Function transaction_begin_commit

tests/transaction_tests.rs:140–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

138
139#[sea_orm_macros::test]
140pub async fn transaction_begin_commit() -> Result<(), DbErr> {
141 let ctx = TestContext::new("transaction_begin_commit_test").await;
142 create_tables(&ctx.db).await?;
143
144 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 0);
145
146 {
147 // Transaction begin in this scope
148 let txn = ctx.db.begin().await?;
149
150 bakery::ActiveModel {
151 name: Set("SeaSide Bakery".to_owned()),
152 profit_margin: Set(10.4),
153 ..Default::default()
154 }
155 .save(&txn)
156 .await?;
157
158 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 1);
159
160 bakery::ActiveModel {
161 name: Set("Top Bakery".to_owned()),
162 profit_margin: Set(15.0),
163 ..Default::default()
164 }
165 .save(&txn)
166 .await?;
167
168 assert_eq!(bakery::Entity::find().all(&txn).await?.len(), 2);
169
170 // Commit changes before the end of scope
171 txn.commit().await?;
172 }
173
174 assert_eq!(bakery::Entity::find().all(&ctx.db).await?.len(), 2);
175
176 ctx.delete().await;
177 Ok(())
178}
179
180#[sea_orm_macros::test]
181pub async fn transaction_begin_rollback() -> Result<(), DbErr> {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected