@@ -197,12 +197,7 @@ fn insert_select() {
197
197
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
198
198
199
199
runtime
200
- . block_on (
201
- client
202
- . prepare ( "CREATE TEMPORARY TABLE foo (id SERIAL, name TEXT)" )
203
- . and_then ( |create| client. execute ( & create, & [ ] ) )
204
- . map ( |n| assert_eq ! ( n, 0 ) ) ,
205
- )
200
+ . block_on ( client. batch_execute ( "CREATE TEMPORARY TABLE foo (id SERIAL, name TEXT)" ) )
206
201
. unwrap ( ) ;
207
202
208
203
let insert = client. prepare ( "INSERT INTO foo (name) VALUES ($1), ($2)" ) ;
@@ -238,14 +233,13 @@ fn cancel_query() {
238
233
let connection = connection. map_err ( |e| panic ! ( "{}" , e) ) ;
239
234
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
240
235
241
- let sleep = client. prepare ( "SELECT pg_sleep(100)" ) ;
242
- let sleep = runtime. block_on ( sleep) . unwrap ( ) ;
243
-
244
- let sleep = client. execute ( & sleep, & [ ] ) . then ( |r| match r {
245
- Ok ( _) => panic ! ( "unexpected success" ) ,
246
- Err ( ref e) if e. code ( ) == Some ( & SqlState :: QUERY_CANCELED ) => Ok :: < ( ) , ( ) > ( ( ) ) ,
247
- Err ( e) => panic ! ( "unexpected error {}" , e) ,
248
- } ) ;
236
+ let sleep = client
237
+ . batch_execute ( "SELECT pg_sleep(100)" )
238
+ . then ( |r| match r {
239
+ Ok ( _) => panic ! ( "unexpected success" ) ,
240
+ Err ( ref e) if e. code ( ) == Some ( & SqlState :: QUERY_CANCELED ) => Ok :: < ( ) , ( ) > ( ( ) ) ,
241
+ Err ( e) => panic ! ( "unexpected error {}" , e) ,
242
+ } ) ;
249
243
let cancel = Delay :: new ( Instant :: now ( ) + Duration :: from_millis ( 100 ) )
250
244
. then ( |r| {
251
245
r. unwrap ( ) ;
@@ -276,17 +270,15 @@ fn custom_enum() {
276
270
let connection = connection. map_err ( |e| panic ! ( "{}" , e) ) ;
277
271
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
278
272
279
- let create_type = client. prepare (
280
- "CREATE TYPE pg_temp.mood AS ENUM (
281
- 'sad',
282
- 'ok',
283
- 'happy'
284
- )" ,
285
- ) ;
286
- let create_type = runtime. block_on ( create_type) . unwrap ( ) ;
287
-
288
- let create_type = client. execute ( & create_type, & [ ] ) ;
289
- runtime. block_on ( create_type) . unwrap ( ) ;
273
+ runtime
274
+ . block_on ( client. batch_execute (
275
+ "CREATE TYPE pg_temp.mood AS ENUM (
276
+ 'sad',
277
+ 'ok',
278
+ 'happy'
279
+ )" ,
280
+ ) )
281
+ . unwrap ( ) ;
290
282
291
283
let select = client. prepare ( "SELECT $1::mood" ) ;
292
284
let select = runtime. block_on ( select) . unwrap ( ) ;
@@ -316,12 +308,11 @@ fn custom_domain() {
316
308
let connection = connection. map_err ( |e| panic ! ( "{}" , e) ) ;
317
309
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
318
310
319
- let create_type =
320
- client. prepare ( "CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16)" ) ;
321
- let create_type = runtime. block_on ( create_type) . unwrap ( ) ;
322
-
323
- let create_type = client. execute ( & create_type, & [ ] ) ;
324
- runtime. block_on ( create_type) . unwrap ( ) ;
311
+ runtime
312
+ . block_on ( client. batch_execute (
313
+ "CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16)" ,
314
+ ) )
315
+ . unwrap ( ) ;
325
316
326
317
let select = client. prepare ( "SELECT $1::session_id" ) ;
327
318
let select = runtime. block_on ( select) . unwrap ( ) ;
@@ -371,17 +362,15 @@ fn custom_composite() {
371
362
let connection = connection. map_err ( |e| panic ! ( "{}" , e) ) ;
372
363
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
373
364
374
- let create_type = client. prepare (
375
- "CREATE TYPE pg_temp.inventory_item AS (
376
- name TEXT,
377
- supplier INTEGER,
378
- price NUMERIC
379
- )" ,
380
- ) ;
381
- let create_type = runtime. block_on ( create_type) . unwrap ( ) ;
382
-
383
- let create_type = client. execute ( & create_type, & [ ] ) ;
384
- runtime. block_on ( create_type) . unwrap ( ) ;
365
+ runtime
366
+ . block_on ( client. batch_execute (
367
+ "CREATE TYPE pg_temp.inventory_item AS (
368
+ name TEXT,
369
+ supplier INTEGER,
370
+ price NUMERIC
371
+ )" ,
372
+ ) )
373
+ . unwrap ( ) ;
385
374
386
375
let select = client. prepare ( "SELECT $1::inventory_item" ) ;
387
376
let select = runtime. block_on ( select) . unwrap ( ) ;
@@ -414,16 +403,14 @@ fn custom_range() {
414
403
let connection = connection. map_err ( |e| panic ! ( "{}" , e) ) ;
415
404
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
416
405
417
- let create_type = client. prepare (
418
- "CREATE TYPE pg_temp.floatrange AS RANGE (
419
- subtype = float8,
420
- subtype_diff = float8mi
421
- )" ,
422
- ) ;
423
- let create_type = runtime. block_on ( create_type) . unwrap ( ) ;
424
-
425
- let create_type = client. execute ( & create_type, & [ ] ) ;
426
- runtime. block_on ( create_type) . unwrap ( ) ;
406
+ runtime
407
+ . block_on ( client. batch_execute (
408
+ "CREATE TYPE pg_temp.floatrange AS RANGE (
409
+ subtype = float8,
410
+ subtype_diff = float8mi
411
+ )" ,
412
+ ) )
413
+ . unwrap ( ) ;
427
414
428
415
let select = client. prepare ( "SELECT $1::floatrange" ) ;
429
416
let select = runtime. block_on ( select) . unwrap ( ) ;
@@ -479,17 +466,17 @@ fn notifications() {
479
466
} ) ;
480
467
runtime. handle ( ) . spawn ( connection) . unwrap ( ) ;
481
468
482
- let listen = client . prepare ( "LISTEN test_notifications" ) ;
483
- let listen = runtime . block_on ( listen ) . unwrap ( ) ;
484
- runtime . block_on ( client . execute ( & listen , & [ ] ) ) . unwrap ( ) ;
469
+ runtime
470
+ . block_on ( client . batch_execute ( "LISTEN test_notifications" ) )
471
+ . unwrap ( ) ;
485
472
486
- let notify = client . prepare ( "NOTIFY test_notifications, 'hello'" ) ;
487
- let notify = runtime . block_on ( notify ) . unwrap ( ) ;
488
- runtime . block_on ( client . execute ( & notify , & [ ] ) ) . unwrap ( ) ;
473
+ runtime
474
+ . block_on ( client . batch_execute ( "NOTIFY test_notifications, 'hello'" ) )
475
+ . unwrap ( ) ;
489
476
490
- let notify = client . prepare ( "NOTIFY test_notifications, 'world'" ) ;
491
- let notify = runtime . block_on ( notify ) . unwrap ( ) ;
492
- runtime . block_on ( client . execute ( & notify , & [ ] ) ) . unwrap ( ) ;
477
+ runtime
478
+ . block_on ( client . batch_execute ( "NOTIFY test_notifications, 'world'" ) )
479
+ . unwrap ( ) ;
493
480
494
481
drop ( client) ;
495
482
runtime. run ( ) . unwrap ( ) ;
0 commit comments