postgres_static_analyzer_reflect_queries/client/async_/
deadpool.rs1use super::generic_client::GenericClient;
4use deadpool_postgres::{
5 Client as DeadpoolClient, ClientWrapper, Transaction as DeadpoolTransaction,
6};
7use tokio_postgres::{
8 Client as PgClient, Error, RowStream, Statement, ToStatement, Transaction as PgTransaction,
9 types::BorrowToSql,
10};
11impl GenericClient for DeadpoolClient {
12 fn stmt_cache() -> bool {
13 true
14 }
15 async fn prepare(&self, query: &str) -> Result<Statement, Error> {
16 ClientWrapper::prepare_cached(self, query).await
17 }
18 async fn execute<T>(
19 &self,
20 query: &T,
21 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
22 ) -> Result<u64, Error>
23 where
24 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
25 {
26 PgClient::execute(self, query, params).await
27 }
28 async fn query_one<T>(
29 &self,
30 statement: &T,
31 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
32 ) -> Result<tokio_postgres::Row, Error>
33 where
34 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
35 {
36 PgClient::query_one(self, statement, params).await
37 }
38 async fn query_opt<T>(
39 &self,
40 statement: &T,
41 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
42 ) -> Result<Option<tokio_postgres::Row>, Error>
43 where
44 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
45 {
46 PgClient::query_opt(self, statement, params).await
47 }
48 async fn query<T>(
49 &self,
50 query: &T,
51 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
52 ) -> Result<Vec<tokio_postgres::Row>, Error>
53 where
54 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
55 {
56 PgClient::query(self, query, params).await
57 }
58 async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
59 where
60 T: ?Sized + ToStatement + Sync + Send,
61 I: IntoIterator + Sync + Send,
62 I::IntoIter: ExactSizeIterator,
63 I::Item: BorrowToSql,
64 {
65 PgClient::query_raw(self, statement, params).await
66 }
67}
68impl GenericClient for DeadpoolTransaction<'_> {
69 fn stmt_cache() -> bool {
70 false
71 }
72 async fn prepare(&self, query: &str) -> Result<Statement, Error> {
73 DeadpoolTransaction::prepare_cached(self, query).await
74 }
75 async fn execute<T>(
76 &self,
77 query: &T,
78 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
79 ) -> Result<u64, Error>
80 where
81 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
82 {
83 PgTransaction::execute(self, query, params).await
84 }
85 async fn query_one<T>(
86 &self,
87 statement: &T,
88 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
89 ) -> Result<tokio_postgres::Row, Error>
90 where
91 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
92 {
93 PgTransaction::query_one(self, statement, params).await
94 }
95 async fn query_opt<T>(
96 &self,
97 statement: &T,
98 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
99 ) -> Result<Option<tokio_postgres::Row>, Error>
100 where
101 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
102 {
103 PgTransaction::query_opt(self, statement, params).await
104 }
105 async fn query<T>(
106 &self,
107 query: &T,
108 params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
109 ) -> Result<Vec<tokio_postgres::Row>, Error>
110 where
111 T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
112 {
113 PgTransaction::query(self, query, params).await
114 }
115 async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
116 where
117 T: ?Sized + ToStatement + Sync + Send,
118 I: IntoIterator + Sync + Send,
119 I::IntoIter: ExactSizeIterator,
120 I::Item: BorrowToSql,
121 {
122 PgTransaction::query_raw(self, statement, params).await
123 }
124}