@@ -11,7 +11,7 @@ use futures::{Future, IntoFuture, BoxFuture, Stream, Sink, Poll, StartSend};
11
11
use futures:: future:: Either ;
12
12
use postgres_protocol:: authentication;
13
13
use postgres_protocol:: message:: { backend, frontend} ;
14
- use postgres_protocol:: message:: backend:: ErrorFields ;
14
+ use postgres_protocol:: message:: backend:: { ErrorResponseBody , ErrorFields } ;
15
15
use postgres_shared:: RowData ;
16
16
use std:: collections:: HashMap ;
17
17
use std:: fmt;
@@ -263,25 +263,22 @@ impl Connection {
263
263
. and_then ( |( m, s) | {
264
264
match m {
265
265
backend:: Message :: ReadyForQuery ( _) => {
266
- Either :: A ( Ok ( ( rows, Connection ( s) ) ) . into_future ( ) )
266
+ Ok ( ( rows, Connection ( s) ) ) . into_future ( ) . boxed ( )
267
267
}
268
268
backend:: Message :: DataRow ( body) => {
269
269
match body. values ( ) . collect ( ) {
270
270
Ok ( row) => {
271
271
rows. push ( row) ;
272
- Either :: B ( Connection ( s) . simple_read_rows ( rows) )
272
+ Connection ( s) . simple_read_rows ( rows)
273
273
}
274
- Err ( e) => Either :: A ( Err ( Error :: Io ( e) ) . into_future ( ) ) ,
274
+ Err ( e) => Err ( Error :: Io ( e) ) . into_future ( ) . boxed ( ) ,
275
275
}
276
276
}
277
277
backend:: Message :: EmptyQueryResponse |
278
- backend:: Message :: CommandComplete ( _) => {
279
- Either :: B ( Connection ( s) . simple_read_rows ( rows) )
280
- }
281
- backend:: Message :: ErrorResponse ( body) => {
282
- Either :: A ( Err ( err ( & mut body. fields ( ) , Connection ( s) ) ) . into_future ( ) )
283
- }
284
- _ => Either :: A ( Err ( bad_message ( ) ) . into_future ( ) ) ,
278
+ backend:: Message :: CommandComplete ( _) |
279
+ backend:: Message :: RowDescription ( _) => Connection ( s) . simple_read_rows ( rows) ,
280
+ backend:: Message :: ErrorResponse ( body) => Connection ( s) . ready_err ( body) ,
281
+ _ => Err ( bad_message ( ) ) . into_future ( ) . boxed ( ) ,
285
282
}
286
283
} )
287
284
. boxed ( )
@@ -293,22 +290,18 @@ impl Connection {
293
290
. and_then ( |( m, s) | {
294
291
match m {
295
292
backend:: Message :: EmptyQueryResponse |
296
- backend:: Message :: CommandComplete ( _) => {
297
- Either :: B ( Connection ( s) . ready ( rows) )
298
- } ,
293
+ backend:: Message :: CommandComplete ( _) => Connection ( s) . ready ( rows) . boxed ( ) ,
299
294
backend:: Message :: DataRow ( body) => {
300
295
match body. values ( ) . collect ( ) {
301
296
Ok ( row) => {
302
297
rows. push ( row) ;
303
- Either :: B ( Connection ( s) . read_rows ( rows) )
298
+ Connection ( s) . read_rows ( rows)
304
299
}
305
- Err ( e) => Either :: A ( Err ( Error :: Io ( e) ) . into_future ( ) ) ,
300
+ Err ( e) => Err ( Error :: Io ( e) ) . into_future ( ) . boxed ( ) ,
306
301
}
307
302
}
308
- backend:: Message :: ErrorResponse ( body) => {
309
- Either :: A ( Err ( err ( & mut body. fields ( ) , Connection ( s) ) ) . into_future ( ) )
310
- }
311
- _ => Either :: A ( Err ( bad_message ( ) ) . into_future ( ) ) ,
303
+ backend:: Message :: ErrorResponse ( body) => Connection ( s) . ready_err ( body) ,
304
+ _ => Err ( bad_message ( ) ) . into_future ( ) . boxed ( ) ,
312
305
}
313
306
} )
314
307
. boxed ( )
@@ -328,6 +321,19 @@ impl Connection {
328
321
. boxed ( )
329
322
}
330
323
324
+ fn ready_err < T > ( self , body : ErrorResponseBody < Vec < u8 > > ) -> BoxFuture < T , Error >
325
+ where T : ' static + Send
326
+ {
327
+ self . ready ( DbError :: new ( & mut body. fields ( ) ) )
328
+ . and_then ( |( e, s) | {
329
+ match e {
330
+ Ok ( e) => Err ( Error :: Db ( Box :: new ( e) , s) ) ,
331
+ Err ( e) => Err ( Error :: Io ( e) ) ,
332
+ }
333
+ } )
334
+ . boxed ( )
335
+ }
336
+
331
337
pub fn batch_execute ( self , query : & str ) -> BoxFuture < Connection , Error > {
332
338
self . simple_query ( query) . map ( |r| r. 1 ) . boxed ( )
333
339
}
0 commit comments