From 45593f5ad0e66bc08789105d4b69bf0a9a434f3b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 28 Dec 2018 20:20:31 -0800 Subject: [PATCH] Rename Query to ToStatement --- postgres/src/client.rs | 10 +++++----- postgres/src/lib.rs | 4 ++-- postgres/src/{query.rs => to_statement.rs} | 6 +++--- postgres/src/transaction.rs | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) rename postgres/src/{query.rs => to_statement.rs} (83%) diff --git a/postgres/src/client.rs b/postgres/src/client.rs index 6f0bea56..c2f691d2 100644 --- a/postgres/src/client.rs +++ b/postgres/src/client.rs @@ -10,7 +10,7 @@ use tokio_postgres::{MakeTlsMode, Socket, TlsMode}; #[cfg(feature = "runtime")] use crate::Builder; -use crate::{Query, Statement, Transaction}; +use crate::{Statement, ToStatement, Transaction}; pub struct Client(tokio_postgres::Client); @@ -42,7 +42,7 @@ impl Client { pub fn execute(&mut self, query: &T, params: &[&dyn ToSql]) -> Result where - T: ?Sized + Query, + T: ?Sized + ToStatement, { let statement = query.__statement(self)?; self.0.execute(&statement.0, params).wait() @@ -50,7 +50,7 @@ impl Client { pub fn query(&mut self, query: &T, params: &[&dyn ToSql]) -> Result, Error> where - T: ?Sized + Query, + T: ?Sized + ToStatement, { let statement = query.__statement(self)?; self.0.query(&statement.0, params).collect().wait() @@ -63,7 +63,7 @@ impl Client { reader: R, ) -> Result where - T: ?Sized + Query, + T: ?Sized + ToStatement, R: Read, { let statement = query.__statement(self)?; @@ -78,7 +78,7 @@ impl Client { params: &[&dyn ToSql], ) -> Result, Error> where - T: ?Sized + Query, + T: ?Sized + ToStatement, { let statement = query.__statement(self)?; let mut stream = self.0.copy_out(&statement.0, params).wait(); diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index d555e821..197be698 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -7,8 +7,8 @@ use tokio::runtime::{self, Runtime}; mod builder; mod client; mod portal; -mod query; mod statement; +mod to_statement; mod transaction; #[cfg(feature = "runtime")] @@ -19,8 +19,8 @@ mod test; pub use crate::builder::*; pub use crate::client::*; pub use crate::portal::*; -pub use crate::query::*; pub use crate::statement::*; +pub use crate::to_statement::*; pub use crate::transaction::*; #[cfg(feature = "runtime")] diff --git a/postgres/src/query.rs b/postgres/src/to_statement.rs similarity index 83% rename from postgres/src/query.rs rename to postgres/src/to_statement.rs index 4910fcd0..2f24d203 100644 --- a/postgres/src/query.rs +++ b/postgres/src/to_statement.rs @@ -6,14 +6,14 @@ mod sealed { pub trait Sealed {} } -pub trait Query: sealed::Sealed { +pub trait ToStatement: sealed::Sealed { #[doc(hidden)] fn __statement(&self, client: &mut Client) -> Result; } impl sealed::Sealed for str {} -impl Query for str { +impl ToStatement for str { fn __statement(&self, client: &mut Client) -> Result { client.prepare(self) } @@ -21,7 +21,7 @@ impl Query for str { impl sealed::Sealed for Statement {} -impl Query for Statement { +impl ToStatement for Statement { fn __statement(&self, _: &mut Client) -> Result { Ok(self.clone()) } diff --git a/postgres/src/transaction.rs b/postgres/src/transaction.rs index e526d527..2c2e180c 100644 --- a/postgres/src/transaction.rs +++ b/postgres/src/transaction.rs @@ -3,7 +3,7 @@ use std::io::Read; use tokio_postgres::types::{ToSql, Type}; use tokio_postgres::{Error, Row}; -use crate::{Client, CopyOutReader, Portal, Query, Statement}; +use crate::{Client, CopyOutReader, Portal, Statement, ToStatement}; pub struct Transaction<'a> { client: &'a mut Client, @@ -62,21 +62,21 @@ impl<'a> Transaction<'a> { pub fn execute(&mut self, query: &T, params: &[&dyn ToSql]) -> Result where - T: ?Sized + Query, + T: ?Sized + ToStatement, { self.client.execute(query, params) } pub fn query(&mut self, query: &T, params: &[&dyn ToSql]) -> Result, Error> where - T: ?Sized + Query, + T: ?Sized + ToStatement, { self.client.query(query, params) } pub fn bind(&mut self, query: &T, params: &[&dyn ToSql]) -> Result where - T: ?Sized + Query, + T: ?Sized + ToStatement, { let statement = query.__statement(&mut self.client)?; self.client @@ -101,7 +101,7 @@ impl<'a> Transaction<'a> { reader: R, ) -> Result where - T: ?Sized + Query, + T: ?Sized + ToStatement, R: Read, { self.client.copy_in(query, params, reader) @@ -113,7 +113,7 @@ impl<'a> Transaction<'a> { params: &[&dyn ToSql], ) -> Result, Error> where - T: ?Sized + Query, + T: ?Sized + ToStatement, { self.client.copy_out(query, params) }