@@ -21,7 +21,6 @@ use postgres_protocol::message::{backend, frontend};
2121use postgres_protocol:: message:: backend:: { ErrorResponseBody , ErrorFields } ;
2222use postgres_shared:: RowData ;
2323use std:: collections:: HashMap ;
24- use std:: error:: Error as StdError ;
2524use std:: fmt;
2625use std:: io;
2726use std:: mem;
@@ -37,9 +36,11 @@ use params::{ConnectParams, IntoConnectParams};
3736use stream:: PostgresStream ;
3837use tls:: Handshake ;
3938use 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 ;
4141
4242pub mod error;
43+ pub mod rows;
4344mod stream;
4445pub mod tls;
4546pub mod transaction;
@@ -900,7 +901,7 @@ impl Connection {
900901 -> BoxStateStream < Row , Connection , Error > {
901902 let columns = statement. columns . clone ( ) ;
902903 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 ) ) )
904905 . flatten_state_stream ( )
905906 . boxed ( )
906907 }
@@ -949,50 +950,6 @@ impl Statement {
949950 }
950951}
951952
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-
996953fn connect_err ( fields : & mut ErrorFields ) -> ConnectError {
997954 match DbError :: new ( fields) {
998955 Ok ( err) => ConnectError :: Db ( Box :: new ( err) ) ,
@@ -1006,6 +963,10 @@ fn bad_message<T>() -> T
1006963 io:: Error :: new ( io:: ErrorKind :: InvalidInput , "unexpected message" ) . into ( )
1007964}
1008965
966+ trait RowNew {
967+ fn new ( columns : Arc < Vec < Column > > , data : RowData ) -> Row ;
968+ }
969+
1009970trait TransactionNew {
1010971 fn new ( c : Connection ) -> Transaction ;
1011972}
0 commit comments