Skip to main content

postgres_static_analyzer_reflect_queries/client/async_/
generic_client.rs

1// This file was generated with `clorinde`. Do not modify.
2
3use std::future::Future;
4use tokio_postgres::{
5    Client, Error, Row, RowStream, Statement, ToStatement, Transaction,
6    types::{BorrowToSql, ToSql},
7};
8/// Abstraction over multiple types of asynchronous clients.
9/// This allows you to use tokio_postgres clients and transactions interchangeably.
10///
11/// In addition, when the `deadpool` feature is enabled (default), this trait also
12/// abstracts over deadpool clients and transactions
13pub trait GenericClient: Send + Sync {
14    fn stmt_cache() -> bool {
15        false
16    }
17    fn prepare(&self, query: &str) -> impl Future<Output = Result<Statement, Error>> + Send;
18    fn execute<T>(
19        &self,
20        query: &T,
21        params: &[&(dyn ToSql + Sync)],
22    ) -> impl Future<Output = Result<u64, Error>> + Send
23    where
24        T: ?Sized + ToStatement + Sync + Send;
25    fn query_one<T>(
26        &self,
27        statement: &T,
28        params: &[&(dyn ToSql + Sync)],
29    ) -> impl Future<Output = Result<Row, Error>> + Send
30    where
31        T: ?Sized + ToStatement + Sync + Send;
32    fn query_opt<T>(
33        &self,
34        statement: &T,
35        params: &[&(dyn ToSql + Sync)],
36    ) -> impl Future<Output = Result<Option<Row>, Error>> + Send
37    where
38        T: ?Sized + ToStatement + Sync + Send;
39    fn query<T>(
40        &self,
41        query: &T,
42        params: &[&(dyn ToSql + Sync)],
43    ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send
44    where
45        T: ?Sized + ToStatement + Sync + Send;
46    fn query_raw<T, I>(
47        &self,
48        statement: &T,
49        params: I,
50    ) -> impl Future<Output = Result<RowStream, Error>> + Send
51    where
52        T: ?Sized + ToStatement + Sync + Send,
53        I: IntoIterator + Sync + Send,
54        I::IntoIter: ExactSizeIterator,
55        I::Item: BorrowToSql;
56}
57impl GenericClient for Transaction<'_> {
58    async fn prepare(&self, query: &str) -> Result<Statement, Error> {
59        Transaction::prepare(self, query).await
60    }
61    async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
62    where
63        T: ?Sized + ToStatement + Sync + Send,
64    {
65        Transaction::execute(self, query, params).await
66    }
67    async fn query_one<T>(
68        &self,
69        statement: &T,
70        params: &[&(dyn ToSql + Sync)],
71    ) -> Result<Row, Error>
72    where
73        T: ?Sized + ToStatement + Sync + Send,
74    {
75        Transaction::query_one(self, statement, params).await
76    }
77    async fn query_opt<T>(
78        &self,
79        statement: &T,
80        params: &[&(dyn ToSql + Sync)],
81    ) -> Result<Option<Row>, Error>
82    where
83        T: ?Sized + ToStatement + Sync + Send,
84    {
85        Transaction::query_opt(self, statement, params).await
86    }
87    async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
88    where
89        T: ?Sized + ToStatement + Sync + Send,
90    {
91        Transaction::query(self, query, params).await
92    }
93    async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
94    where
95        T: ?Sized + ToStatement + Sync + Send,
96        I: IntoIterator + Sync + Send,
97        I::IntoIter: ExactSizeIterator,
98        I::Item: BorrowToSql,
99    {
100        Transaction::query_raw(self, statement, params).await
101    }
102}
103impl GenericClient for Client {
104    async fn prepare(&self, query: &str) -> Result<Statement, Error> {
105        Client::prepare(self, query).await
106    }
107    async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
108    where
109        T: ?Sized + ToStatement + Sync + Send,
110    {
111        Client::execute(self, query, params).await
112    }
113    async fn query_one<T>(
114        &self,
115        statement: &T,
116        params: &[&(dyn ToSql + Sync)],
117    ) -> Result<Row, Error>
118    where
119        T: ?Sized + ToStatement + Sync + Send,
120    {
121        Client::query_one(self, statement, params).await
122    }
123    async fn query_opt<T>(
124        &self,
125        statement: &T,
126        params: &[&(dyn ToSql + Sync)],
127    ) -> Result<Option<Row>, Error>
128    where
129        T: ?Sized + ToStatement + Sync + Send,
130    {
131        Client::query_opt(self, statement, params).await
132    }
133    async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
134    where
135        T: ?Sized + ToStatement + Sync + Send,
136    {
137        Client::query(self, query, params).await
138    }
139    async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
140    where
141        T: ?Sized + ToStatement + Sync + Send,
142        I: IntoIterator + Sync + Send,
143        I::IntoIter: ExactSizeIterator,
144        I::Item: BorrowToSql,
145    {
146        Client::query_raw(self, statement, params).await
147    }
148}