Adding generic for execute function for genericconnection

This commit is contained in:
Colin Maxfield 2019-12-28 16:36:56 -05:00
parent 793e83a4ef
commit 508b430753
3 changed files with 11 additions and 3 deletions

View File

@ -455,7 +455,10 @@ impl Client {
} }
impl GenericConnection for Client { impl GenericConnection for Client {
fn execute(&mut self, query: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error> { fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
T: ?Sized + ToStatement,
{
self.execute(query, params) self.execute(query, params)
} }
fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error> fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>

View File

@ -5,7 +5,9 @@ use tokio_postgres::{Error, Row};
/// A trait allowing abstraction over connections and transactions /// A trait allowing abstraction over connections and transactions
pub trait GenericConnection { pub trait GenericConnection {
/// Like `Client::execute`. /// Like `Client::execute`.
fn execute(&mut self, query: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>; fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
T: ?Sized + ToStatement;
/// Like `Client::query`. /// Like `Client::query`.
fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error> fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>

View File

@ -181,7 +181,10 @@ impl<'a> Transaction<'a> {
} }
impl<'a> GenericConnection for Transaction<'a> { impl<'a> GenericConnection for Transaction<'a> {
fn execute(&mut self, query: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error> { fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
T: ?Sized + ToStatement,
{
self.execute(query, params) self.execute(query, params)
} }
fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error> fn query<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>