@@ -49,42 +49,48 @@ impl ToString for Value {
4949 }
5050}
5151
52- /// RDBC Result type
53- pub type Result < T > = std:: result:: Result < T , Error > ;
54-
5552/// Represents database driver that can be shared between threads, and can therefore implement
5653/// a connection pool
54+ #[ async_trait]
5755pub trait Driver : Sync + Send {
5856 /// The type of connection created by this driver.
5957 type Connection : Connection ;
6058
59+ type Error ;
60+
6161 /// Create a connection to the database. Note that connections are intended to be used
6262 /// in a single thread since most database connections are not thread-safe
63- fn connect ( url : & str ) -> Result < Self :: Connection > ;
63+ async fn connect ( url : & str ) -> Result < Self :: Connection , Self :: Error > ;
6464}
6565
6666/// Represents a connection to a database
67+ #[ async_trait]
6768pub trait Connection {
6869 /// The type of statement produced by this connection.
6970 type Statement : Statement ;
7071
72+ type Error ;
73+
7174 /// Create a statement for execution
72- fn create ( & mut self , sql : & str ) -> Result < Self :: Statement > ;
75+ async fn create ( & mut self , sql : & str ) -> Result < Self :: Statement , Self :: Error > ;
7376
7477 /// Create a prepared statement for execution
75- fn prepare ( & mut self , sql : & str ) -> Result < Self :: Statement > ;
78+ async fn prepare ( & mut self , sql : & str ) -> Result < Self :: Statement , Self :: Error > ;
7679}
7780
7881/// Represents an executable statement
82+ #[ async_trait]
7983pub trait Statement {
8084 /// The type of ResultSet returned by this statement.
8185 type ResultSet : ResultSet ;
8286
87+ type Error ;
88+
8389 /// Execute a query that is expected to return a result set, such as a `SELECT` statement
84- fn execute_query ( & mut self , params : & [ Value ] ) -> Result < Self :: ResultSet > ;
90+ async fn execute_query ( & mut self , params : & [ Value ] ) -> Result < Self :: ResultSet , Self :: Error > ;
8591
8692 /// Execute a query that is expected to update some rows.
87- fn execute_update ( & mut self , params : & [ Value ] ) -> Result < u64 > ;
93+ async fn execute_update ( & mut self , params : & [ Value ] ) -> Result < u64 , Self :: Error > ;
8894}
8995
9096/// Result set from executing a query against a statement
@@ -95,36 +101,40 @@ pub trait ResultSet {
95101 /// The type of row included in this result set.
96102 type Row : Row ;
97103
104+ type Error ;
105+
98106 /// get meta data about this result set
99- fn meta_data ( & self ) -> Result < Self :: MetaData > ;
107+ fn meta_data ( & self ) -> Result < & Self :: MetaData , Self :: Error > ;
100108
101109 /// Get a stream where each item is a batch of rows.
102- async fn batches ( & mut self ) -> Result < Pin < Box < dyn Stream < Item = Vec < Self :: Row > > > > > ;
110+ async fn batches ( & mut self )
111+ -> Result < Pin < Box < dyn Stream < Item = Vec < Self :: Row > > > > , Self :: Error > ;
103112
104113 /// Get a stream of rows.
105114 ///
106115 /// Note that the rows are actually returned from the database in batches;
107116 /// this just flattens the batches to provide a (possibly) simpler API.
108- async fn rows < ' a > ( & ' a mut self ) -> Result < Box < dyn Stream < Item = Self :: Row > + ' a > > {
117+ async fn rows < ' a > ( & ' a mut self ) -> Result < Box < dyn Stream < Item = Self :: Row > + ' a > , Self :: Error > {
109118 Ok ( Box :: new ( self . batches ( ) . await ?. map ( iter) . flatten ( ) ) )
110119 }
111120}
112121
113122pub trait Row {
114- fn get_i8 ( & self , i : u64 ) -> Result < Option < i8 > > ;
115- fn get_i16 ( & self , i : u64 ) -> Result < Option < i16 > > ;
116- fn get_i32 ( & self , i : u64 ) -> Result < Option < i32 > > ;
117- fn get_i64 ( & self , i : u64 ) -> Result < Option < i64 > > ;
118- fn get_f32 ( & self , i : u64 ) -> Result < Option < f32 > > ;
119- fn get_f64 ( & self , i : u64 ) -> Result < Option < f64 > > ;
120- fn get_string ( & self , i : u64 ) -> Result < Option < String > > ;
121- fn get_bytes ( & self , i : u64 ) -> Result < Option < Vec < u8 > > > ;
123+ type Error ;
124+ fn get_i8 ( & self , i : u64 ) -> Result < Option < i8 > , Self :: Error > ;
125+ fn get_i16 ( & self , i : u64 ) -> Result < Option < i16 > , Self :: Error > ;
126+ fn get_i32 ( & self , i : u64 ) -> Result < Option < i32 > , Self :: Error > ;
127+ fn get_i64 ( & self , i : u64 ) -> Result < Option < i64 > , Self :: Error > ;
128+ fn get_f32 ( & self , i : u64 ) -> Result < Option < f32 > , Self :: Error > ;
129+ fn get_f64 ( & self , i : u64 ) -> Result < Option < f64 > , Self :: Error > ;
130+ fn get_string ( & self , i : u64 ) -> Result < Option < String > , Self :: Error > ;
131+ fn get_bytes ( & self , i : u64 ) -> Result < Option < Vec < u8 > > , Self :: Error > ;
122132}
123133
124134/// Meta data for result set
125135pub trait MetaData {
126136 fn num_columns ( & self ) -> u64 ;
127- fn column_name ( & self , i : u64 ) -> String ;
137+ fn column_name ( & self , i : u64 ) -> & str ;
128138 fn column_type ( & self , i : u64 ) -> DataType ;
129139}
130140
@@ -166,8 +176,8 @@ impl MetaData for Vec<Column> {
166176 self . len ( ) as u64
167177 }
168178
169- fn column_name ( & self , i : u64 ) -> String {
170- self [ i as usize ] . name . clone ( )
179+ fn column_name ( & self , i : u64 ) -> & str {
180+ & self [ i as usize ] . name
171181 }
172182
173183 fn column_type ( & self , i : u64 ) -> DataType {
0 commit comments