@@ -3,6 +3,7 @@ use crate::cancel_query;
33use crate :: codec:: BackendMessages ;
44use crate :: config:: { Host , SslMode } ;
55use crate :: connection:: { Request , RequestMessages } ;
6+ use crate :: query:: RowStream ;
67use crate :: slice_iter;
78#[ cfg( feature = "runtime" ) ]
89use crate :: tls:: MakeTlsConnect ;
@@ -18,7 +19,7 @@ use crate::{Error, Statement};
1819use bytes:: { Bytes , IntoBuf } ;
1920use fallible_iterator:: FallibleIterator ;
2021use futures:: channel:: mpsc;
21- use futures:: { future, Stream , TryFutureExt , TryStream } ;
22+ use futures:: { future, Stream , TryFutureExt , TryStream , TryStreamExt } ;
2223use futures:: { ready, StreamExt } ;
2324use parking_lot:: Mutex ;
2425use postgres_protocol:: message:: backend:: Message ;
@@ -190,40 +191,40 @@ impl Client {
190191 prepare:: prepare ( & self . inner , query, parameter_types) . await
191192 }
192193
193- /// Executes a statement, returning a stream of the resulting rows.
194+ /// Executes a statement, returning a vector of the resulting rows.
194195 ///
195196 /// # Panics
196197 ///
197198 /// Panics if the number of parameters provided does not match the number expected.
198- pub fn query < ' a , T > (
199- & ' a self ,
200- statement : & ' a T ,
201- params : & ' a [ & ( dyn ToSql + Sync ) ] ,
202- ) -> impl Stream < Item = Result < Row , Error > > + ' a
199+ pub async fn query < T > (
200+ & self ,
201+ statement : & T ,
202+ params : & [ & ( dyn ToSql + Sync ) ] ,
203+ ) -> Result < Vec < Row > , Error >
203204 where
204205 T : ?Sized + ToStatement ,
205206 {
206- self . query_iter ( statement, slice_iter ( params) )
207+ self . query_raw ( statement, slice_iter ( params) )
208+ . await ?
209+ . try_collect ( )
210+ . await
207211 }
208212
209- /// Like [`query`], but takes an iterator of parameters rather than a slice.
213+ /// The maximally flexible version of [`query`].
214+ ///
215+ /// # Panics
216+ ///
217+ /// Panics if the number of parameters provided does not match the number expected.
210218 ///
211219 /// [`query`]: #method.query
212- pub fn query_iter < ' a , T , I > (
213- & ' a self ,
214- statement : & ' a T ,
215- params : I ,
216- ) -> impl Stream < Item = Result < Row , Error > > + ' a
220+ pub async fn query_raw < ' a , T , I > ( & self , statement : & T , params : I ) -> Result < RowStream , Error >
217221 where
218222 T : ?Sized + ToStatement ,
219- I : IntoIterator < Item = & ' a dyn ToSql > + ' a ,
223+ I : IntoIterator < Item = & ' a dyn ToSql > ,
220224 I :: IntoIter : ExactSizeIterator ,
221225 {
222- let f = async move {
223- let statement = statement. __convert ( ) . into_statement ( self ) . await ?;
224- Ok ( query:: query ( & self . inner , statement, params) )
225- } ;
226- f. try_flatten_stream ( )
226+ let statement = statement. __convert ( ) . into_statement ( self ) . await ?;
227+ query:: query ( & self . inner , statement, params) . await
227228 }
228229
229230 /// Executes a statement, returning the number of rows modified.
@@ -241,13 +242,17 @@ impl Client {
241242 where
242243 T : ?Sized + ToStatement ,
243244 {
244- self . execute_iter ( statement, slice_iter ( params) ) . await
245+ self . execute_raw ( statement, slice_iter ( params) ) . await
245246 }
246247
247- /// Like [`execute`], but takes an iterator of parameters rather than a slice.
248+ /// The maximally flexible version of [`execute`].
249+ ///
250+ /// # Panics
251+ ///
252+ /// Panics if the number of parameters provided does not match the number expected.
248253 ///
249254 /// [`execute`]: #method.execute
250- pub async fn execute_iter < ' a , T , I > ( & self , statement : & T , params : I ) -> Result < u64 , Error >
255+ pub async fn execute_raw < ' a , T , I > ( & self , statement : & T , params : I ) -> Result < u64 , Error >
251256 where
252257 T : ?Sized + ToStatement ,
253258 I : IntoIterator < Item = & ' a dyn ToSql > ,
0 commit comments