From 643602d2b63423e2a804a8321f575cb0a5b2d1d9 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 22 Dec 2016 18:47:05 -0500 Subject: [PATCH] Move execute to Connection --- postgres-tokio/src/lib.rs | 15 ++++++--------- postgres-tokio/src/test.rs | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/postgres-tokio/src/lib.rs b/postgres-tokio/src/lib.rs index 955ba580..f8184561 100644 --- a/postgres-tokio/src/lib.rs +++ b/postgres-tokio/src/lib.rs @@ -579,6 +579,12 @@ impl Connection { .boxed() } + pub fn execute(self, statement: &Statement, params: &[&ToSql]) -> BoxFuture<(u64, Connection), Error> { + self.raw_execute(&statement.name, "", &statement.params, params) + .and_then(|conn| conn.finish_execute()) + .boxed() + } + pub fn close(self) -> BoxFuture<(), Error> { let mut terminate = vec![]; frontend::terminate(&mut terminate); @@ -615,15 +621,6 @@ impl Statement { pub fn columns(&self) -> &[Column] { &self.columns } - - pub fn execute(&self, - params: &[&ToSql], - conn: Connection) - -> BoxFuture<(u64, Connection), Error> { - conn.raw_execute(&self.name, "", &self.params, params) - .and_then(|conn| conn.finish_execute()) - .boxed() - } } pub struct Row { diff --git a/postgres-tokio/src/test.rs b/postgres-tokio/src/test.rs index 53e24991..6ccff1e2 100644 --- a/postgres-tokio/src/test.rs +++ b/postgres-tokio/src/test.rs @@ -112,12 +112,12 @@ fn prepare_execute() { .then(|c| { c.unwrap().prepare("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, name VARCHAR)") }) - .and_then(|(s, c)| s.execute(&[], c)) + .and_then(|(s, c)| c.execute(&s, &[])) .and_then(|(n, c)| { assert_eq!(0, n); c.prepare("INSERT INTO foo (name) VALUES ($1), ($2)") }) - .and_then(|(s, c)| s.execute(&[&"steven", &"bob"], c)) + .and_then(|(s, c)| c.execute(&s, &[&"steven", &"bob"])) .map(|(n, _)| assert_eq!(n, 2)); l.run(done).unwrap(); }