@@ -313,6 +313,36 @@ impl Client {
313
313
/// Panics if the number of parameters provided does not match the number expected.
314
314
///
315
315
/// [`query`]: #method.query
316
+ ///
317
+ /// # Examples
318
+ ///
319
+ /// If you have a type like `Vec<T>` where `T: ToSql` Rust will not know how to use it as params. To get around
320
+ /// this the type must explicitly be converted to `&dyn ToSql`.
321
+ ///
322
+ /// ```no_run
323
+ /// # { #![cfg(feature = "runtime")] // tokio_postgres::connect doesn't exist without "runtime"
324
+ /// # use tokio_postgres::{Client, NoTls};
325
+ /// # async fn async_main() -> Result<(), tokio_postgres::Error> {
326
+ /// # let (client, _) = tokio_postgres::connect("host=localhost user=postgres", NoTls).await?;
327
+ /// use tokio_postgres::types::ToSql;
328
+ /// use futures::StreamExt;
329
+ ///
330
+ /// let params: Vec<String> = vec![
331
+ /// "first param".into(),
332
+ /// "second param".into(),
333
+ /// ];
334
+ /// let mut it = Box::pin(client.query_raw(
335
+ /// "SELECT foo FROM bar WHERE biz = $1 AND baz = $2",
336
+ /// params.iter().map(|p| p as &dyn ToSql),
337
+ /// ).await?);
338
+ ///
339
+ /// while let Some(row) = it.next().await.transpose()? {
340
+ /// let foo: i32 = row.get("foo");
341
+ /// println!("foo: {}", foo);
342
+ /// }
343
+ /// # Ok(())
344
+ /// # } }
345
+ /// ```
316
346
pub async fn query_raw < ' a , T , I > ( & self , statement : & T , params : I ) -> Result < RowStream , Error >
317
347
where
318
348
T : ?Sized + ToStatement ,
0 commit comments