@@ -188,19 +188,13 @@ async fn test_column_override_nullable() -> anyhow::Result<()> {
188
188
189
189
async fn with_test_row < ' a > (
190
190
conn : & ' a mut MySqlConnection ,
191
- ) -> anyhow:: Result < Transaction < ' a , MySql > > {
191
+ ) -> anyhow:: Result < ( Transaction < ' a , MySql > , MyInt ) > {
192
192
let mut transaction = conn. begin ( ) . await ?;
193
- sqlx:: query!( "INSERT INTO tweet(text, owner_id) VALUES ('#sqlx is pretty cool!', 1)" )
193
+ let id = sqlx:: query!( "INSERT INTO tweet(text, owner_id) VALUES ('#sqlx is pretty cool!', 1)" )
194
194
. execute ( & mut transaction)
195
- . await ?;
196
- Ok ( transaction)
197
- }
198
-
199
- async fn last_insert_id ( conn : & mut MySqlConnection ) -> anyhow:: Result < MyInt > {
200
- let result = sqlx:: query!( "SELECT last_insert_id() AS last_insert_id" )
201
- . fetch_one ( conn)
202
- . await ?;
203
- Ok ( MyInt ( result. last_insert_id as i64 ) )
195
+ . await ?
196
+ . last_insert_id ( ) ;
197
+ Ok ( ( transaction, MyInt ( id as i64 ) ) )
204
198
}
205
199
206
200
#[ derive( PartialEq , Eq , Debug , sqlx:: Type ) ]
@@ -218,8 +212,7 @@ struct OptionalRecord {
218
212
#[ sqlx_macros:: test]
219
213
async fn test_column_override_wildcard ( ) -> anyhow:: Result < ( ) > {
220
214
let mut conn = new :: < MySql > ( ) . await ?;
221
- let mut conn = with_test_row ( & mut conn) . await ?;
222
- let id = last_insert_id ( & mut conn) . await ?;
215
+ let ( mut conn, id) = with_test_row ( & mut conn) . await ?;
223
216
224
217
let record = sqlx:: query_as!( Record , "select id as `id: _` from tweet" )
225
218
. fetch_one ( & mut conn)
@@ -246,7 +239,7 @@ async fn test_column_override_wildcard() -> anyhow::Result<()> {
246
239
#[ sqlx_macros:: test]
247
240
async fn test_column_override_wildcard_not_null ( ) -> anyhow:: Result < ( ) > {
248
241
let mut conn = new :: < MySql > ( ) . await ?;
249
- let mut conn = with_test_row ( & mut conn) . await ?;
242
+ let ( mut conn, _ ) = with_test_row ( & mut conn) . await ?;
250
243
251
244
let record = sqlx:: query_as!( Record , "select owner_id as `id!: _` from tweet" )
252
245
. fetch_one ( & mut conn)
@@ -260,8 +253,7 @@ async fn test_column_override_wildcard_not_null() -> anyhow::Result<()> {
260
253
#[ sqlx_macros:: test]
261
254
async fn test_column_override_wildcard_nullable ( ) -> anyhow:: Result < ( ) > {
262
255
let mut conn = new :: < MySql > ( ) . await ?;
263
- let mut conn = with_test_row ( & mut conn) . await ?;
264
- let id = last_insert_id ( & mut conn) . await ?;
256
+ let ( mut conn, id) = with_test_row ( & mut conn) . await ?;
265
257
266
258
let record = sqlx:: query_as!( OptionalRecord , "select id as `id?: _` from tweet" )
267
259
. fetch_one ( & mut conn)
@@ -275,8 +267,7 @@ async fn test_column_override_wildcard_nullable() -> anyhow::Result<()> {
275
267
#[ sqlx_macros:: test]
276
268
async fn test_column_override_exact ( ) -> anyhow:: Result < ( ) > {
277
269
let mut conn = new :: < MySql > ( ) . await ?;
278
- let mut conn = with_test_row ( & mut conn) . await ?;
279
- let id = last_insert_id ( & mut conn) . await ?;
270
+ let ( mut conn, id) = with_test_row ( & mut conn) . await ?;
280
271
281
272
let record = sqlx:: query!( "select id as `id: MyInt` from tweet" )
282
273
. fetch_one ( & mut conn)
@@ -303,7 +294,7 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
303
294
#[ sqlx_macros:: test]
304
295
async fn test_column_override_exact_not_null ( ) -> anyhow:: Result < ( ) > {
305
296
let mut conn = new :: < MySql > ( ) . await ?;
306
- let mut conn = with_test_row ( & mut conn) . await ?;
297
+ let ( mut conn, _ ) = with_test_row ( & mut conn) . await ?;
307
298
308
299
let record = sqlx:: query!( "select owner_id as `id!: MyInt` from tweet" )
309
300
. fetch_one ( & mut conn)
@@ -317,8 +308,7 @@ async fn test_column_override_exact_not_null() -> anyhow::Result<()> {
317
308
#[ sqlx_macros:: test]
318
309
async fn test_column_override_exact_nullable ( ) -> anyhow:: Result < ( ) > {
319
310
let mut conn = new :: < MySql > ( ) . await ?;
320
- let mut conn = with_test_row ( & mut conn) . await ?;
321
- let id = last_insert_id ( & mut conn) . await ?;
311
+ let ( mut conn, id) = with_test_row ( & mut conn) . await ?;
322
312
323
313
let record = sqlx:: query!( "select id as `id?: MyInt` from tweet" )
324
314
. fetch_one ( & mut conn)
0 commit comments