Merge pull request #561 from dvic/add-methods-generic-client
Add missing methods to GenericClient
This commit is contained in:
commit
5429a79997
@ -506,28 +506,72 @@ impl Client {
|
||||
|
||||
#[async_trait]
|
||||
impl GenericClient for Client {
|
||||
async fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.execute(query, params).await
|
||||
}
|
||||
|
||||
async fn query<T>(
|
||||
&mut self,
|
||||
query: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Vec<Row>, Error>
|
||||
async fn execute_raw<'b, I, T>(&self, statement: &T, params: I) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
self.execute_raw(statement, params).await
|
||||
}
|
||||
|
||||
async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query(query, params).await
|
||||
}
|
||||
|
||||
async fn prepare(&mut self, query: &str) -> Result<Statement, Error> {
|
||||
async fn query_one<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Row, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query_one(statement, params).await
|
||||
}
|
||||
|
||||
async fn query_opt<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Option<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query_opt(statement, params).await
|
||||
}
|
||||
|
||||
async fn query_raw<'b, T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
self.query_raw(statement, params).await
|
||||
}
|
||||
|
||||
async fn prepare(&self, query: &str) -> Result<Statement, Error> {
|
||||
self.prepare(query).await
|
||||
}
|
||||
|
||||
async fn prepare_typed(
|
||||
&self,
|
||||
query: &str,
|
||||
parameter_types: &[Type],
|
||||
) -> Result<Statement, Error> {
|
||||
self.prepare_typed(query, parameter_types).await
|
||||
}
|
||||
|
||||
async fn transaction(&mut self) -> Result<Transaction<'_>, Error> {
|
||||
self.transaction().await
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::types::ToSql;
|
||||
use crate::query::RowStream;
|
||||
use crate::types::{ToSql, Type};
|
||||
use crate::{Error, Row, Statement, ToStatement, Transaction};
|
||||
use async_trait::async_trait;
|
||||
|
||||
@ -6,21 +7,56 @@ use async_trait::async_trait;
|
||||
#[async_trait]
|
||||
pub trait GenericClient {
|
||||
/// Like `Client::execute`.
|
||||
async fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send;
|
||||
|
||||
/// Like `Client::execute_raw`.
|
||||
async fn execute_raw<'b, I, T>(&self, statement: &T, params: I) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator;
|
||||
|
||||
/// Like `Client::query`.
|
||||
async fn query<T>(
|
||||
&mut self,
|
||||
query: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Vec<Row>, Error>
|
||||
async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send;
|
||||
|
||||
/// Like `Client::query_one`.
|
||||
async fn query_one<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Row, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send;
|
||||
|
||||
/// Like `Client::query_opt`.
|
||||
async fn query_opt<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Option<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send;
|
||||
|
||||
/// Like `Client::query_raw`.
|
||||
async fn query_raw<'b, T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator;
|
||||
|
||||
/// Like `Client::prepare`.
|
||||
async fn prepare(&mut self, query: &str) -> Result<Statement, Error>;
|
||||
async fn prepare(&self, query: &str) -> Result<Statement, Error>;
|
||||
|
||||
/// Like `Client::prepare_typed`.
|
||||
async fn prepare_typed(
|
||||
&self,
|
||||
query: &str,
|
||||
parameter_types: &[Type],
|
||||
) -> Result<Statement, Error>;
|
||||
|
||||
/// Like `Client::transaction`.
|
||||
async fn transaction(&mut self) -> Result<Transaction<'_>, Error>;
|
||||
|
@ -289,28 +289,72 @@ impl<'a> Transaction<'a> {
|
||||
|
||||
#[async_trait]
|
||||
impl crate::GenericClient for Transaction<'_> {
|
||||
async fn execute<T>(&mut self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.execute(query, params).await
|
||||
}
|
||||
|
||||
async fn query<T>(
|
||||
&mut self,
|
||||
query: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Vec<Row>, Error>
|
||||
async fn execute_raw<'b, I, T>(&self, statement: &T, params: I) -> Result<u64, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
self.execute_raw(statement, params).await
|
||||
}
|
||||
|
||||
async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query(query, params).await
|
||||
}
|
||||
|
||||
async fn prepare(&mut self, query: &str) -> Result<Statement, Error> {
|
||||
async fn query_one<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Row, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query_one(statement, params).await
|
||||
}
|
||||
|
||||
async fn query_opt<T>(
|
||||
&self,
|
||||
statement: &T,
|
||||
params: &[&(dyn ToSql + Sync)],
|
||||
) -> Result<Option<Row>, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
{
|
||||
self.query_opt(statement, params).await
|
||||
}
|
||||
|
||||
async fn query_raw<'b, T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
|
||||
where
|
||||
T: ?Sized + ToStatement + Sync + Send,
|
||||
I: IntoIterator<Item = &'b dyn ToSql> + Sync + Send,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
self.query_raw(statement, params).await
|
||||
}
|
||||
|
||||
async fn prepare(&self, query: &str) -> Result<Statement, Error> {
|
||||
self.prepare(query).await
|
||||
}
|
||||
|
||||
async fn prepare_typed(
|
||||
&self,
|
||||
query: &str,
|
||||
parameter_types: &[Type],
|
||||
) -> Result<Statement, Error> {
|
||||
self.prepare_typed(query, parameter_types).await
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_lifetimes)]
|
||||
async fn transaction<'a>(&'a mut self) -> Result<Transaction<'a>, Error> {
|
||||
self.transaction().await
|
||||
|
Loading…
Reference in New Issue
Block a user