@@ -21,7 +21,6 @@ use postgres_protocol::message::{backend, frontend};
21
21
use postgres_protocol:: message:: backend:: { ErrorResponseBody , ErrorFields } ;
22
22
use postgres_shared:: RowData ;
23
23
use std:: collections:: HashMap ;
24
- use std:: error:: Error as StdError ;
25
24
use std:: fmt;
26
25
use std:: io;
27
26
use std:: mem;
@@ -37,9 +36,11 @@ use params::{ConnectParams, IntoConnectParams};
37
36
use stream:: PostgresStream ;
38
37
use tls:: Handshake ;
39
38
use transaction:: Transaction ;
40
- use types:: { Oid , Type , ToSql , SessionInfo , IsNull , FromSql , WrongType , Other , Kind , Field } ;
39
+ use types:: { Oid , Type , ToSql , SessionInfo , IsNull , FromSql , Other , Kind , Field } ;
40
+ use rows:: Row ;
41
41
42
42
pub mod error;
43
+ pub mod rows;
43
44
mod stream;
44
45
pub mod tls;
45
46
pub mod transaction;
@@ -900,7 +901,7 @@ impl Connection {
900
901
-> BoxStateStream < Row , Connection , Error > {
901
902
let columns = statement. columns . clone ( ) ;
902
903
self . raw_execute ( & statement. name , "" , & statement. params , params)
903
- . map ( |c| c. read_rows ( ) . map ( move |r| Row { columns : columns. clone ( ) , data : r } ) )
904
+ . map ( |c| c. read_rows ( ) . map ( move |r| Row :: new ( columns. clone ( ) , r ) ) )
904
905
. flatten_state_stream ( )
905
906
. boxed ( )
906
907
}
@@ -949,50 +950,6 @@ impl Statement {
949
950
}
950
951
}
951
952
952
- pub struct Row {
953
- columns : Arc < Vec < Column > > ,
954
- data : RowData ,
955
- }
956
-
957
- impl Row {
958
- pub fn columns ( & self ) -> & [ Column ] {
959
- & self . columns
960
- }
961
-
962
- pub fn len ( & self ) -> usize {
963
- self . columns . len ( )
964
- }
965
-
966
- pub fn get < T , I > ( & self , idx : I ) -> T
967
- where T : FromSql ,
968
- I : RowIndex + fmt:: Debug
969
- {
970
- match self . try_get ( & idx) {
971
- Ok ( Some ( v) ) => v,
972
- Ok ( None ) => panic ! ( "no such column {:?}" , idx) ,
973
- Err ( e) => panic ! ( "error retrieving row {:?}: {}" , idx, e) ,
974
- }
975
- }
976
-
977
- pub fn try_get < T , I > ( & self , idx : I ) -> Result < Option < T > , Box < StdError + Sync + Send > >
978
- where T : FromSql ,
979
- I : RowIndex
980
- {
981
- let idx = match idx. idx ( & self . columns ) {
982
- Some ( idx) => idx,
983
- None => return Ok ( None ) ,
984
- } ;
985
-
986
- let ty = self . columns [ idx] . type_ ( ) ;
987
- if !T :: accepts ( ty) {
988
- return Err ( Box :: new ( WrongType :: new ( ty. clone ( ) ) ) ) ;
989
- }
990
-
991
- // FIXME
992
- T :: from_sql_nullable ( ty, self . data . get ( idx) , & SessionInfo :: new ( & HashMap :: new ( ) ) ) . map ( Some )
993
- }
994
- }
995
-
996
953
fn connect_err ( fields : & mut ErrorFields ) -> ConnectError {
997
954
match DbError :: new ( fields) {
998
955
Ok ( err) => ConnectError :: Db ( Box :: new ( err) ) ,
@@ -1006,6 +963,10 @@ fn bad_message<T>() -> T
1006
963
io:: Error :: new ( io:: ErrorKind :: InvalidInput , "unexpected message" ) . into ( )
1007
964
}
1008
965
966
+ trait RowNew {
967
+ fn new ( columns : Arc < Vec < Column > > , data : RowData ) -> Row ;
968
+ }
969
+
1009
970
trait TransactionNew {
1010
971
fn new ( c : Connection ) -> Transaction ;
1011
972
}
0 commit comments