diff --git a/postgres/src/query.rs b/postgres/src/query.rs index 7376fa99..99332e53 100644 --- a/postgres/src/query.rs +++ b/postgres/src/query.rs @@ -21,6 +21,11 @@ impl<'a> Query<'a> { _p: PhantomData, } } + + /// A convenience API which collects the resulting rows into a `Vec` and returns them. + pub fn to_vec(self) -> Result, Error> { + self.collect() + } } impl<'a> FallibleIterator for Query<'a> { diff --git a/postgres/src/query_portal.rs b/postgres/src/query_portal.rs index d2ee4067..75f380c2 100644 --- a/postgres/src/query_portal.rs +++ b/postgres/src/query_portal.rs @@ -21,6 +21,11 @@ impl<'a> QueryPortal<'a> { _p: PhantomData, } } + + /// A convenience API which collects the resulting rows into a `Vec` and returns them. + pub fn to_vec(self) -> Result, Error> { + self.collect() + } } impl<'a> FallibleIterator for QueryPortal<'a> { diff --git a/postgres/src/test.rs b/postgres/src/test.rs index ed6242a1..89e71bc3 100644 --- a/postgres/src/test.rs +++ b/postgres/src/test.rs @@ -1,4 +1,3 @@ -use fallible_iterator::FallibleIterator; use std::io::Read; use tokio_postgres::types::Type; use tokio_postgres::NoTls; @@ -21,11 +20,7 @@ fn query_prepared() { let mut client = Client::connect("host=localhost port=5433 user=postgres", NoTls).unwrap(); let stmt = client.prepare("SELECT $1::TEXT").unwrap(); - let rows = client - .query(&stmt, &[&"hello"]) - .unwrap() - .collect::>() - .unwrap(); + let rows = client.query(&stmt, &[&"hello"]).unwrap().to_vec().unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, &str>(0), "hello"); } @@ -37,7 +32,7 @@ fn query_unprepared() { let rows = client .query("SELECT $1::TEXT", &[&"hello"]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, &str>(0), "hello"); @@ -62,7 +57,7 @@ fn transaction_commit() { let rows = client .query("SELECT * FROM foo", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, i32>(0), 1); @@ -87,7 +82,7 @@ fn transaction_rollback() { let rows = client .query("SELECT * FROM foo", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 0); } @@ -111,7 +106,7 @@ fn transaction_drop() { let rows = client .query("SELECT * FROM foo", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 0); } @@ -141,7 +136,7 @@ fn nested_transactions() { let rows = transaction .query("SELECT id FROM foo ORDER BY id", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, i32>(0), 1); @@ -165,7 +160,7 @@ fn nested_transactions() { let rows = client .query("SELECT id FROM foo ORDER BY id", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 3); assert_eq!(rows[0].get::<_, i32>(0), 1); @@ -192,7 +187,7 @@ fn copy_in() { let rows = client .query("SELECT id, name FROM foo ORDER BY id", &[]) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 2); @@ -251,7 +246,7 @@ fn portal() { let rows = transaction .query_portal(&portal, 2) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 2); assert_eq!(rows[0].get::<_, i32>(0), 1); @@ -260,7 +255,7 @@ fn portal() { let rows = transaction .query_portal(&portal, 2) .unwrap() - .collect::>() + .to_vec() .unwrap(); assert_eq!(rows.len(), 1); assert_eq!(rows[0].get::<_, i32>(0), 3);