Skip to content

Commit 2495b40

Browse files
committed
Fix CI.
1 parent be539d2 commit 2495b40

File tree

6 files changed

+165
-57
lines changed

6 files changed

+165
-57
lines changed

examples/basic/src/operation.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ pub async fn insert_and_update(db: &DbConn) -> Result<(), DbErr> {
2222
};
2323
let res = Fruit::insert(pear).exec(db).await?;
2424

25-
println!("Inserted: last_insert_id = {}", res.last_insert_id);
26-
27-
let pear: Option<fruit::Model> = Fruit::find_by_id(res.last_insert_id).one(db).await?;
25+
println!(
26+
"Inserted: last_insert_id = {}",
27+
res.last_insert_id.ok_or(DbErr::UnpackInsertId)?
28+
);
29+
30+
let pear: Option<fruit::Model> =
31+
Fruit::find_by_id(res.last_insert_id.ok_or(DbErr::UnpackInsertId)?)
32+
.one(db)
33+
.await?;
2834

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

examples/graphql_example/service/src/mutation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Mutation {
1313
let res = Note::insert(active_model).exec(db).await?;
1414

1515
Ok(note::Model {
16-
id: res.last_insert_id,
16+
id: res.last_insert_id.ok_or(DbErr::UnpackInsertId)?,
1717
..form_data
1818
})
1919
}

examples/proxy_gluesql_example/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl ProxyDatabaseTrait for ProxyDb {
125125
});
126126

127127
Ok(ProxyExecResult {
128-
last_insert_id: 1,
128+
last_insert_id: Some(1),
129129
rows_affected: 1,
130130
})
131131
}

examples/seaography_example/migration/src/m20230102_000001_seed_bakery_data.rs

+80-16
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,46 @@ impl MigrationTrait for Migration {
1515
profit_margin: Set(10.4),
1616
..Default::default()
1717
};
18-
let sea = Bakery::insert(bakery).exec(db).await?.last_insert_id;
18+
let sea = Bakery::insert(bakery)
19+
.exec(db)
20+
.await?
21+
.last_insert_id
22+
.ok_or(DbErr::UnpackInsertId)?;
1923

2024
let bakery = bakery::ActiveModel {
2125
name: Set("LakeSide Bakery".to_owned()),
2226
profit_margin: Set(5.8),
2327
..Default::default()
2428
};
25-
let lake = Bakery::insert(bakery).exec(db).await?.last_insert_id;
29+
let lake = Bakery::insert(bakery)
30+
.exec(db)
31+
.await?
32+
.last_insert_id
33+
.ok_or(DbErr::UnpackInsertId)?;
2634

2735
let alice = baker::ActiveModel {
2836
name: Set("Alice".to_owned()),
2937
contact: Set("+44 15273388".to_owned()),
3038
bakery_id: Set(Some(sea)),
3139
..Default::default()
3240
};
33-
let alice = Baker::insert(alice).exec(db).await?.last_insert_id;
41+
let alice = Baker::insert(alice)
42+
.exec(db)
43+
.await?
44+
.last_insert_id
45+
.ok_or(DbErr::UnpackInsertId)?;
3446

3547
let bob = baker::ActiveModel {
3648
name: Set("Bob".to_owned()),
3749
contact: Set("+852 12345678".to_owned()),
3850
bakery_id: Set(Some(lake)),
3951
..Default::default()
4052
};
41-
let bob = Baker::insert(bob).exec(db).await?.last_insert_id;
53+
let bob = Baker::insert(bob)
54+
.exec(db)
55+
.await?
56+
.last_insert_id
57+
.ok_or(DbErr::UnpackInsertId)?;
4258

4359
let cake = cake::ActiveModel {
4460
name: Set("Chocolate Cake".to_owned()),
@@ -47,7 +63,11 @@ impl MigrationTrait for Migration {
4763
bakery_id: Set(Some(sea)),
4864
..Default::default()
4965
};
50-
let choco = Cake::insert(cake).exec(db).await?.last_insert_id;
66+
let choco = Cake::insert(cake)
67+
.exec(db)
68+
.await?
69+
.last_insert_id
70+
.ok_or(DbErr::UnpackInsertId)?;
5171

5272
let mut cake = cake::ActiveModel {
5373
name: Set("Double Chocolate".to_owned()),
@@ -56,9 +76,17 @@ impl MigrationTrait for Migration {
5676
bakery_id: Set(Some(sea)),
5777
..Default::default()
5878
};
59-
let double_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
79+
let double_1 = Cake::insert(cake.clone())
80+
.exec(db)
81+
.await?
82+
.last_insert_id
83+
.ok_or(DbErr::UnpackInsertId)?;
6084
cake.bakery_id = Set(Some(lake));
61-
let double_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
85+
let double_2 = Cake::insert(cake)
86+
.exec(db)
87+
.await?
88+
.last_insert_id
89+
.ok_or(DbErr::UnpackInsertId)?;
6290

6391
let mut cake = cake::ActiveModel {
6492
name: Set("Lemon Cake".to_owned()),
@@ -67,9 +95,17 @@ impl MigrationTrait for Migration {
6795
bakery_id: Set(Some(sea)),
6896
..Default::default()
6997
};
70-
let lemon_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
98+
let lemon_1 = Cake::insert(cake.clone())
99+
.exec(db)
100+
.await?
101+
.last_insert_id
102+
.ok_or(DbErr::UnpackInsertId)?;
71103
cake.bakery_id = Set(Some(lake));
72-
let lemon_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
104+
let lemon_2 = Cake::insert(cake)
105+
.exec(db)
106+
.await?
107+
.last_insert_id
108+
.ok_or(DbErr::UnpackInsertId)?;
73109

74110
let mut cake = cake::ActiveModel {
75111
name: Set("Strawberry Cake".to_owned()),
@@ -78,9 +114,17 @@ impl MigrationTrait for Migration {
78114
bakery_id: Set(Some(sea)),
79115
..Default::default()
80116
};
81-
let straw_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
117+
let straw_1 = Cake::insert(cake.clone())
118+
.exec(db)
119+
.await?
120+
.last_insert_id
121+
.ok_or(DbErr::UnpackInsertId)?;
82122
cake.bakery_id = Set(Some(lake));
83-
let straw_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
123+
let straw_2 = Cake::insert(cake)
124+
.exec(db)
125+
.await?
126+
.last_insert_id
127+
.ok_or(DbErr::UnpackInsertId)?;
84128

85129
let cake = cake::ActiveModel {
86130
name: Set("Orange Cake".to_owned()),
@@ -89,7 +133,11 @@ impl MigrationTrait for Migration {
89133
bakery_id: Set(Some(lake)),
90134
..Default::default()
91135
};
92-
let orange = Cake::insert(cake).exec(db).await?.last_insert_id;
136+
let orange = Cake::insert(cake)
137+
.exec(db)
138+
.await?
139+
.last_insert_id
140+
.ok_or(DbErr::UnpackInsertId)?;
93141

94142
let mut cake = cake::ActiveModel {
95143
name: Set("New York Cheese".to_owned()),
@@ -98,9 +146,17 @@ impl MigrationTrait for Migration {
98146
bakery_id: Set(Some(sea)),
99147
..Default::default()
100148
};
101-
let cheese_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
149+
let cheese_1 = Cake::insert(cake.clone())
150+
.exec(db)
151+
.await?
152+
.last_insert_id
153+
.ok_or(DbErr::UnpackInsertId)?;
102154
cake.bakery_id = Set(Some(lake));
103-
let cheese_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
155+
let cheese_2 = Cake::insert(cake)
156+
.exec(db)
157+
.await?
158+
.last_insert_id
159+
.ok_or(DbErr::UnpackInsertId)?;
104160

105161
let mut cake = cake::ActiveModel {
106162
name: Set("Blueburry Cheese".to_owned()),
@@ -109,9 +165,17 @@ impl MigrationTrait for Migration {
109165
bakery_id: Set(Some(sea)),
110166
..Default::default()
111167
};
112-
let blue_1 = Cake::insert(cake.clone()).exec(db).await?.last_insert_id;
168+
let blue_1 = Cake::insert(cake.clone())
169+
.exec(db)
170+
.await?
171+
.last_insert_id
172+
.ok_or(DbErr::UnpackInsertId)?;
113173
cake.bakery_id = Set(Some(lake));
114-
let blue_2 = Cake::insert(cake).exec(db).await?.last_insert_id;
174+
let blue_2 = Cake::insert(cake)
175+
.exec(db)
176+
.await?
177+
.last_insert_id
178+
.ok_or(DbErr::UnpackInsertId)?;
115179

116180
let rel = cake_baker::ActiveModel {
117181
cake_id: Set(choco),

issues/1357/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async fn main() -> Result<()> {
2424
.await?;
2525

2626
assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
27-
assert_eq!(res.last_insert_id, model.id);
27+
assert_eq!(res.last_insert_id, Some(model.id));
2828

2929
let model = Model {
3030
id: -10,
@@ -36,7 +36,7 @@ async fn main() -> Result<()> {
3636
.await?;
3737

3838
assert_eq!(Entity::find().one(&db).await?, Some(model.clone()));
39-
assert_eq!(res.last_insert_id, model.id);
39+
assert_eq!(res.last_insert_id, Some(model.id));
4040

4141
Ok(())
4242
}

0 commit comments

Comments
 (0)