From e5a724670ddfa497b0d7cbe985f96264079e392c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Fri, 18 Oct 2024 00:28:58 +0800 Subject: [PATCH] Revert "Fix CI." This reverts commit 2495b4016e846386036dc05c3901a00d75c41df1. --- examples/basic/src/operation.rs | 12 +- .../graphql_example/service/src/mutation.rs | 2 +- examples/proxy_gluesql_example/src/main.rs | 2 +- .../src/m20230102_000001_seed_bakery_data.rs | 96 +++------------- issues/1357/src/main.rs | 4 +- tests/relational_tests.rs | 106 ++++++------------ 6 files changed, 57 insertions(+), 165 deletions(-) diff --git a/examples/basic/src/operation.rs b/examples/basic/src/operation.rs index 5c2e0facd..ceae382a7 100644 --- a/examples/basic/src/operation.rs +++ b/examples/basic/src/operation.rs @@ -22,15 +22,9 @@ pub async fn insert_and_update(db: &DbConn) -> Result<(), DbErr> { }; let res = Fruit::insert(pear).exec(db).await?; - println!( - "Inserted: last_insert_id = {}", - res.last_insert_id.ok_or(DbErr::UnpackInsertId)? - ); - - let pear: Option = - Fruit::find_by_id(res.last_insert_id.ok_or(DbErr::UnpackInsertId)?) - .one(db) - .await?; + println!("Inserted: last_insert_id = {}", res.last_insert_id); + + let pear: Option = Fruit::find_by_id(res.last_insert_id).one(db).await?; println!("Pear: {pear:?}"); diff --git a/examples/graphql_example/service/src/mutation.rs b/examples/graphql_example/service/src/mutation.rs index 9b196c67b..1f2447fba 100644 --- a/examples/graphql_example/service/src/mutation.rs +++ b/examples/graphql_example/service/src/mutation.rs @@ -13,7 +13,7 @@ impl Mutation { let res = Note::insert(active_model).exec(db).await?; Ok(note::Model { - id: res.last_insert_id.ok_or(DbErr::UnpackInsertId)?, + id: res.last_insert_id, ..form_data }) } diff --git a/examples/proxy_gluesql_example/src/main.rs b/examples/proxy_gluesql_example/src/main.rs index 56b1f0128..e10109f1c 100644 --- a/examples/proxy_gluesql_example/src/main.rs +++ b/examples/proxy_gluesql_example/src/main.rs @@ -132,7 +132,7 @@ impl ProxyDatabaseTrait for ProxyDb { }); Ok(ProxyExecResult { - last_insert_id: Some(1), + last_insert_id: 1, rows_affected: 1, }) } diff --git a/examples/seaography_example/migration/src/m20230102_000001_seed_bakery_data.rs b/examples/seaography_example/migration/src/m20230102_000001_seed_bakery_data.rs index e11166b8e..3303bfc06 100644 --- a/examples/seaography_example/migration/src/m20230102_000001_seed_bakery_data.rs +++ b/examples/seaography_example/migration/src/m20230102_000001_seed_bakery_data.rs @@ -15,22 +15,14 @@ impl MigrationTrait for Migration { profit_margin: Set(10.4), ..Default::default() }; - let sea = Bakery::insert(bakery) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let sea = Bakery::insert(bakery).exec(db).await?.last_insert_id; let bakery = bakery::ActiveModel { name: Set("LakeSide Bakery".to_owned()), profit_margin: Set(5.8), ..Default::default() }; - let lake = Bakery::insert(bakery) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let lake = Bakery::insert(bakery).exec(db).await?.last_insert_id; let alice = baker::ActiveModel { name: Set("Alice".to_owned()), @@ -38,11 +30,7 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let alice = Baker::insert(alice) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let alice = Baker::insert(alice).exec(db).await?.last_insert_id; let bob = baker::ActiveModel { name: Set("Bob".to_owned()), @@ -50,11 +38,7 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(lake)), ..Default::default() }; - let bob = Baker::insert(bob) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let bob = Baker::insert(bob).exec(db).await?.last_insert_id; let cake = cake::ActiveModel { name: Set("Chocolate Cake".to_owned()), @@ -63,11 +47,7 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let choco = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let choco = Cake::insert(cake).exec(db).await?.last_insert_id; let mut cake = cake::ActiveModel { name: Set("Double Chocolate".to_owned()), @@ -76,17 +56,9 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let double_1 = Cake::insert(cake.clone()) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let double_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id; cake.bakery_id = Set(Some(lake)); - let double_2 = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let double_2 = Cake::insert(cake).exec(db).await?.last_insert_id; let mut cake = cake::ActiveModel { name: Set("Lemon Cake".to_owned()), @@ -95,17 +67,9 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let lemon_1 = Cake::insert(cake.clone()) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let lemon_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id; cake.bakery_id = Set(Some(lake)); - let lemon_2 = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let lemon_2 = Cake::insert(cake).exec(db).await?.last_insert_id; let mut cake = cake::ActiveModel { name: Set("Strawberry Cake".to_owned()), @@ -114,17 +78,9 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let straw_1 = Cake::insert(cake.clone()) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let straw_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id; cake.bakery_id = Set(Some(lake)); - let straw_2 = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let straw_2 = Cake::insert(cake).exec(db).await?.last_insert_id; let cake = cake::ActiveModel { name: Set("Orange Cake".to_owned()), @@ -133,11 +89,7 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(lake)), ..Default::default() }; - let orange = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let orange = Cake::insert(cake).exec(db).await?.last_insert_id; let mut cake = cake::ActiveModel { name: Set("New York Cheese".to_owned()), @@ -146,17 +98,9 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let cheese_1 = Cake::insert(cake.clone()) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let cheese_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id; cake.bakery_id = Set(Some(lake)); - let cheese_2 = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let cheese_2 = Cake::insert(cake).exec(db).await?.last_insert_id; let mut cake = cake::ActiveModel { name: Set("Blueburry Cheese".to_owned()), @@ -165,17 +109,9 @@ impl MigrationTrait for Migration { bakery_id: Set(Some(sea)), ..Default::default() }; - let blue_1 = Cake::insert(cake.clone()) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let blue_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id; cake.bakery_id = Set(Some(lake)); - let blue_2 = Cake::insert(cake) - .exec(db) - .await? - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?; + let blue_2 = Cake::insert(cake).exec(db).await?.last_insert_id; let rel = cake_baker::ActiveModel { cake_id: Set(choco), diff --git a/issues/1357/src/main.rs b/issues/1357/src/main.rs index 3d7ecf4b5..f7488beb4 100644 --- a/issues/1357/src/main.rs +++ b/issues/1357/src/main.rs @@ -24,7 +24,7 @@ async fn main() -> Result<()> { .await?; assert_eq!(Entity::find().one(&db).await?, Some(model.clone())); - assert_eq!(res.last_insert_id, Some(model.id)); + assert_eq!(res.last_insert_id, model.id); let model = Model { id: -10, @@ -36,7 +36,7 @@ async fn main() -> Result<()> { .await?; assert_eq!(Entity::find().one(&db).await?, Some(model.clone())); - assert_eq!(res.last_insert_id, Some(model.id)); + assert_eq!(res.last_insert_id, model.id); Ok(()) } diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 9cb202dc2..29b041c70 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -503,7 +503,7 @@ pub async fn related() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" })), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let _baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?; @@ -514,7 +514,7 @@ pub async fn related() -> Result<(), DbErr> { contact_details: Set(serde_json::json!({ "mobile": "+85212345678", })), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let _baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?; @@ -535,7 +535,7 @@ pub async fn related() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" })), - bakery_id: Set(terres_bakery_res.last_insert_id), + bakery_id: Set(Some(terres_bakery_res.last_insert_id)), ..Default::default() }; let _baker_ada_res = Baker::insert(baker_ada).exec(&ctx.db).await?; @@ -679,7 +679,7 @@ pub async fn related() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" }), - bakery_id: seaside_bakery_res.last_insert_id, + bakery_id: Some(seaside_bakery_res.last_insert_id), }, baker::Model { id: 2, @@ -687,7 +687,7 @@ pub async fn related() -> Result<(), DbErr> { contact_details: serde_json::json!({ "mobile": "+85212345678", }), - bakery_id: seaside_bakery_res.last_insert_id, + bakery_id: Some(seaside_bakery_res.last_insert_id), } ] ), @@ -705,7 +705,7 @@ pub async fn related() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" }), - bakery_id: terres_bakery_res.last_insert_id, + bakery_id: Some(terres_bakery_res.last_insert_id), }] ), ( @@ -749,7 +749,7 @@ pub async fn linked() -> Result<(), DbErr> { "home": "0395555555", "address": "12 Test St, Testville, Vic, Australia" })), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let baker_bob_res = Baker::insert(baker_bob).exec(&ctx.db).await?; @@ -758,13 +758,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(rust_dec(10.25)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let mud_cake_res = Cake::insert(mud_cake).exec(&ctx.db).await?; let bob_cakes_bakers = cakes_bakers::ActiveModel { - cake_id: Set(mud_cake_res.last_insert_id.ok_or(DbErr::UnpackInsertId)?), - baker_id: Set(baker_bob_res.last_insert_id.ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(mud_cake_res.last_insert_id), + baker_id: Set(baker_bob_res.last_insert_id), }; CakesBakers::insert(bob_cakes_bakers).exec(&ctx.db).await?; @@ -774,7 +774,7 @@ pub async fn linked() -> Result<(), DbErr> { contact_details: Set(serde_json::json!({ "mobile": "+85212345678", })), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let baker_bobby_res = Baker::insert(baker_bobby).exec(&ctx.db).await?; @@ -783,17 +783,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(rust_dec(20.5)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let cheese_cake_res = Cake::insert(cheese_cake).exec(&ctx.db).await?; let bobby_cakes_bakers = cakes_bakers::ActiveModel { - cake_id: Set(cheese_cake_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - baker_id: Set(baker_bobby_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(cheese_cake_res.last_insert_id), + baker_id: Set(baker_bobby_res.last_insert_id), }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) @@ -803,17 +799,13 @@ pub async fn linked() -> Result<(), DbErr> { price: Set(rust_dec(30.15)), gluten_free: Set(false), serial: Set(Uuid::new_v4()), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let chocolate_cake_res = Cake::insert(chocolate_cake).exec(&ctx.db).await?; let bobby_cakes_bakers = cakes_bakers::ActiveModel { - cake_id: Set(chocolate_cake_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - baker_id: Set(baker_bobby_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(chocolate_cake_res.last_insert_id), + baker_id: Set(baker_bobby_res.last_insert_id), }; CakesBakers::insert(bobby_cakes_bakers) .exec(&ctx.db) @@ -825,7 +817,7 @@ pub async fn linked() -> Result<(), DbErr> { contact_details: Set(serde_json::json!({ "mobile": "+85298765432", })), - bakery_id: Set(seaside_bakery_res.last_insert_id), + bakery_id: Set(Some(seaside_bakery_res.last_insert_id)), ..Default::default() }; let _baker_freerider_res = Baker::insert(baker_freerider).exec(&ctx.db).await?; @@ -838,24 +830,16 @@ pub async fn linked() -> Result<(), DbErr> { }; let customer_kate_res = Customer::insert(customer_kate).exec(&ctx.db).await?; let kate_order_1 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - customer_id: Set(customer_kate_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kate_res.last_insert_id), total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kate_order_1_res = Order::insert(kate_order_1).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(cheese_cake_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - order_id: Set(kate_order_1_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(cheese_cake_res.last_insert_id), + order_id: Set(kate_order_1_res.last_insert_id), price: Set(rust_dec(7.55)), quantity: Set(2), ..Default::default() @@ -863,24 +847,16 @@ pub async fn linked() -> Result<(), DbErr> { .save(&ctx.db) .await?; let kate_order_2 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - customer_id: Set(customer_kate_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kate_res.last_insert_id), total: Set(rust_dec(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kate_order_2_res = Order::insert(kate_order_2).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(chocolate_cake_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - order_id: Set(kate_order_2_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(chocolate_cake_res.last_insert_id), + order_id: Set(kate_order_2_res.last_insert_id), price: Set(rust_dec(9.9)), quantity: Set(3), ..Default::default() @@ -896,22 +872,16 @@ pub async fn linked() -> Result<(), DbErr> { }; let customer_kara_res = Customer::insert(customer_kara).exec(&ctx.db).await?; let kara_order_1 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - customer_id: Set(customer_kara_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kara_res.last_insert_id), total: Set(rust_dec(15.10)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kara_order_1_res = Order::insert(kara_order_1).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(mud_cake_res.last_insert_id.ok_or(DbErr::UnpackInsertId)?), - order_id: Set(kara_order_1_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(mud_cake_res.last_insert_id), + order_id: Set(kara_order_1_res.last_insert_id), price: Set(rust_dec(7.55)), quantity: Set(2), ..Default::default() @@ -919,24 +889,16 @@ pub async fn linked() -> Result<(), DbErr> { .save(&ctx.db) .await?; let kara_order_2 = order::ActiveModel { - bakery_id: Set(seaside_bakery_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - customer_id: Set(customer_kara_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + bakery_id: Set(seaside_bakery_res.last_insert_id), + customer_id: Set(customer_kara_res.last_insert_id), total: Set(rust_dec(29.7)), placed_at: Set(Utc::now().naive_utc()), ..Default::default() }; let kara_order_2_res = Order::insert(kara_order_2).exec(&ctx.db).await?; lineitem::ActiveModel { - cake_id: Set(cheese_cake_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), - order_id: Set(kara_order_2_res - .last_insert_id - .ok_or(DbErr::UnpackInsertId)?), + cake_id: Set(cheese_cake_res.last_insert_id), + order_id: Set(kara_order_2_res.last_insert_id), price: Set(rust_dec(9.9)), quantity: Set(3), ..Default::default()