Skip to content

Commit 34a68c0

Browse files
authored
Merge pull request #1142 from vsuryamurthy/add_simple_query_generic_client
add simple_query to GenericClient in tokio_postgres
2 parents 20749d8 + d5d75d3 commit 34a68c0

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

tokio-postgres/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Disable `rustc-serialize` compatibility of `eui48-1` dependency
66
* Remove tests for `eui48-04`
77
* Add `table_oid` and `field_id` fields to `Columns` struct of prepared statements.
8+
* Add `GenericClient::simple_query`.
89

910
## v0.7.10 - 2023-08-25
1011

tokio-postgres/src/generic_client.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::query::RowStream;
22
use crate::types::{BorrowToSql, ToSql, Type};
3-
use crate::{Client, Error, Row, Statement, ToStatement, Transaction};
3+
use crate::{Client, Error, Row, SimpleQueryMessage, Statement, ToStatement, Transaction};
44
use async_trait::async_trait;
55

66
mod private {
@@ -12,25 +12,25 @@ mod private {
1212
/// This trait is "sealed", and cannot be implemented outside of this crate.
1313
#[async_trait]
1414
pub trait GenericClient: private::Sealed {
15-
/// Like `Client::execute`.
15+
/// Like [`Client::execute`].
1616
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
1717
where
1818
T: ?Sized + ToStatement + Sync + Send;
1919

20-
/// Like `Client::execute_raw`.
20+
/// Like [`Client::execute_raw`].
2121
async fn execute_raw<P, I, T>(&self, statement: &T, params: I) -> Result<u64, Error>
2222
where
2323
T: ?Sized + ToStatement + Sync + Send,
2424
P: BorrowToSql,
2525
I: IntoIterator<Item = P> + Sync + Send,
2626
I::IntoIter: ExactSizeIterator;
2727

28-
/// Like `Client::query`.
28+
/// Like [`Client::query`].
2929
async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
3030
where
3131
T: ?Sized + ToStatement + Sync + Send;
3232

33-
/// Like `Client::query_one`.
33+
/// Like [`Client::query_one`].
3434
async fn query_one<T>(
3535
&self,
3636
statement: &T,
@@ -39,7 +39,7 @@ pub trait GenericClient: private::Sealed {
3939
where
4040
T: ?Sized + ToStatement + Sync + Send;
4141

42-
/// Like `Client::query_opt`.
42+
/// Like [`Client::query_opt`].
4343
async fn query_opt<T>(
4444
&self,
4545
statement: &T,
@@ -48,31 +48,34 @@ pub trait GenericClient: private::Sealed {
4848
where
4949
T: ?Sized + ToStatement + Sync + Send;
5050

51-
/// Like `Client::query_raw`.
51+
/// Like [`Client::query_raw`].
5252
async fn query_raw<T, P, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
5353
where
5454
T: ?Sized + ToStatement + Sync + Send,
5555
P: BorrowToSql,
5656
I: IntoIterator<Item = P> + Sync + Send,
5757
I::IntoIter: ExactSizeIterator;
5858

59-
/// Like `Client::prepare`.
59+
/// Like [`Client::prepare`].
6060
async fn prepare(&self, query: &str) -> Result<Statement, Error>;
6161

62-
/// Like `Client::prepare_typed`.
62+
/// Like [`Client::prepare_typed`].
6363
async fn prepare_typed(
6464
&self,
6565
query: &str,
6666
parameter_types: &[Type],
6767
) -> Result<Statement, Error>;
6868

69-
/// Like `Client::transaction`.
69+
/// Like [`Client::transaction`].
7070
async fn transaction(&mut self) -> Result<Transaction<'_>, Error>;
7171

72-
/// Like `Client::batch_execute`.
72+
/// Like [`Client::batch_execute`].
7373
async fn batch_execute(&self, query: &str) -> Result<(), Error>;
7474

75-
/// Returns a reference to the underlying `Client`.
75+
/// Like [`Client::simple_query`].
76+
async fn simple_query(&self, query: &str) -> Result<Vec<SimpleQueryMessage>, Error>;
77+
78+
/// Returns a reference to the underlying [`Client`].
7679
fn client(&self) -> &Client;
7780
}
7881

@@ -156,6 +159,10 @@ impl GenericClient for Client {
156159
self.batch_execute(query).await
157160
}
158161

162+
async fn simple_query(&self, query: &str) -> Result<Vec<SimpleQueryMessage>, Error> {
163+
self.simple_query(query).await
164+
}
165+
159166
fn client(&self) -> &Client {
160167
self
161168
}
@@ -243,6 +250,10 @@ impl GenericClient for Transaction<'_> {
243250
self.batch_execute(query).await
244251
}
245252

253+
async fn simple_query(&self, query: &str) -> Result<Vec<SimpleQueryMessage>, Error> {
254+
self.simple_query(query).await
255+
}
256+
246257
fn client(&self) -> &Client {
247258
self.client()
248259
}

0 commit comments

Comments
 (0)