Skip to content

Commit

Permalink
Fix CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
langyo committed Oct 14, 2024
1 parent be539d2 commit 2495b40
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 57 deletions.
12 changes: 9 additions & 3 deletions examples/basic/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ 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);

let pear: Option<fruit::Model> = Fruit::find_by_id(res.last_insert_id).one(db).await?;
println!(
"Inserted: last_insert_id = {}",
res.last_insert_id.ok_or(DbErr::UnpackInsertId)?
);

let pear: Option<fruit::Model> =
Fruit::find_by_id(res.last_insert_id.ok_or(DbErr::UnpackInsertId)?)
.one(db)
.await?;

println!("Pear: {pear:?}");

Expand Down
2 changes: 1 addition & 1 deletion examples/graphql_example/service/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Mutation {
let res = Note::insert(active_model).exec(db).await?;

Ok(note::Model {
id: res.last_insert_id,
id: res.last_insert_id.ok_or(DbErr::UnpackInsertId)?,
..form_data
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy_gluesql_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ProxyDatabaseTrait for ProxyDb {
});

Ok(ProxyExecResult {
last_insert_id: 1,
last_insert_id: Some(1),
rows_affected: 1,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,46 @@ impl MigrationTrait for Migration {
profit_margin: Set(10.4),
..Default::default()
};
let sea = Bakery::insert(bakery).exec(db).await?.last_insert_id;
let sea = Bakery::insert(bakery)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

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;
let lake = Bakery::insert(bakery)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let alice = baker::ActiveModel {
name: Set("Alice".to_owned()),
contact: Set("+44 15273388".to_owned()),
bakery_id: Set(Some(sea)),
..Default::default()
};
let alice = Baker::insert(alice).exec(db).await?.last_insert_id;
let alice = Baker::insert(alice)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let bob = baker::ActiveModel {
name: Set("Bob".to_owned()),
contact: Set("+852 12345678".to_owned()),
bakery_id: Set(Some(lake)),
..Default::default()
};
let bob = Baker::insert(bob).exec(db).await?.last_insert_id;
let bob = Baker::insert(bob)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let cake = cake::ActiveModel {
name: Set("Chocolate Cake".to_owned()),
Expand All @@ -47,7 +63,11 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let choco = Cake::insert(cake).exec(db).await?.last_insert_id;
let choco = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let mut cake = cake::ActiveModel {
name: Set("Double Chocolate".to_owned()),
Expand All @@ -56,9 +76,17 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let double_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
let double_1 = Cake::insert(cake.clone())
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;
cake.bakery_id = Set(Some(lake));
let double_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
let double_2 = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let mut cake = cake::ActiveModel {
name: Set("Lemon Cake".to_owned()),
Expand All @@ -67,9 +95,17 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let lemon_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
let lemon_1 = Cake::insert(cake.clone())
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;
cake.bakery_id = Set(Some(lake));
let lemon_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
let lemon_2 = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let mut cake = cake::ActiveModel {
name: Set("Strawberry Cake".to_owned()),
Expand All @@ -78,9 +114,17 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let straw_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
let straw_1 = Cake::insert(cake.clone())
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;
cake.bakery_id = Set(Some(lake));
let straw_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
let straw_2 = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let cake = cake::ActiveModel {
name: Set("Orange Cake".to_owned()),
Expand All @@ -89,7 +133,11 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(lake)),
..Default::default()
};
let orange = Cake::insert(cake).exec(db).await?.last_insert_id;
let orange = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let mut cake = cake::ActiveModel {
name: Set("New York Cheese".to_owned()),
Expand All @@ -98,9 +146,17 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let cheese_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
let cheese_1 = Cake::insert(cake.clone())
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;
cake.bakery_id = Set(Some(lake));
let cheese_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
let cheese_2 = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let mut cake = cake::ActiveModel {
name: Set("Blueburry Cheese".to_owned()),
Expand All @@ -109,9 +165,17 @@ impl MigrationTrait for Migration {
bakery_id: Set(Some(sea)),
..Default::default()
};
let blue_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
let blue_1 = Cake::insert(cake.clone())
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;
cake.bakery_id = Set(Some(lake));
let blue_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
let blue_2 = Cake::insert(cake)
.exec(db)
.await?
.last_insert_id
.ok_or(DbErr::UnpackInsertId)?;

let rel = cake_baker::ActiveModel {
cake_id: Set(choco),
Expand Down
4 changes: 2 additions & 2 deletions issues/1357/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, model.id);
assert_eq!(res.last_insert_id, Some(model.id));

let model = Model {
id: -10,
Expand All @@ -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, model.id);
assert_eq!(res.last_insert_id, Some(model.id));

Ok(())
}
Loading

0 comments on commit 2495b40

Please sign in to comment.