Move execute to Connection

This commit is contained in:
Steven Fackler 2016-12-22 18:47:05 -05:00
parent 38b491bffb
commit 643602d2b6
2 changed files with 8 additions and 11 deletions

View File

@ -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 {

View File

@ -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();
}