Line data Source code
1 : #![allow(async_fn_in_trait)]
2 :
3 : use crate::query::RowStream;
4 : use crate::types::Type;
5 : use crate::{Client, Error, Transaction};
6 : use postgres_protocol2::Oid;
7 :
8 : mod private {
9 : pub trait Sealed {}
10 : }
11 :
12 : /// A trait allowing abstraction over connections and transactions.
13 : ///
14 : /// This trait is "sealed", and cannot be implemented outside of this crate.
15 : pub trait GenericClient: private::Sealed {
16 : /// Like `Client::query_raw_txt`.
17 : async fn query_raw_txt<S, I>(&self, statement: &str, params: I) -> Result<RowStream, Error>
18 : where
19 : S: AsRef<str> + Sync + Send,
20 : I: IntoIterator<Item = Option<S>> + Sync + Send,
21 : I::IntoIter: ExactSizeIterator + Sync + Send;
22 :
23 : /// Query for type information
24 : async fn get_type(&self, oid: Oid) -> Result<Type, Error>;
25 : }
26 :
27 : impl private::Sealed for Client {}
28 :
29 : impl GenericClient for Client {
30 0 : async fn query_raw_txt<S, I>(&self, statement: &str, params: I) -> Result<RowStream, Error>
31 0 : where
32 0 : S: AsRef<str> + Sync + Send,
33 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
34 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
35 0 : {
36 0 : self.query_raw_txt(statement, params).await
37 0 : }
38 :
39 : /// Query for type information
40 0 : async fn get_type(&self, oid: Oid) -> Result<Type, Error> {
41 0 : crate::prepare::get_type(self.inner(), oid).await
42 0 : }
43 : }
44 :
45 : impl private::Sealed for Transaction<'_> {}
46 :
47 : impl GenericClient for Transaction<'_> {
48 0 : async fn query_raw_txt<S, I>(&self, statement: &str, params: I) -> Result<RowStream, Error>
49 0 : where
50 0 : S: AsRef<str> + Sync + Send,
51 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
52 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
53 0 : {
54 0 : self.query_raw_txt(statement, params).await
55 0 : }
56 :
57 : /// Query for type information
58 0 : async fn get_type(&self, oid: Oid) -> Result<Type, Error> {
59 0 : self.client().get_type(oid).await
60 0 : }
61 : }
|