sentinel_driver/
generic_client.rs1use crate::error::Result;
2use crate::row::{Row, SimpleQueryMessage};
3use crate::types::ToSql;
4use crate::Connection;
5
6#[allow(async_fn_in_trait)]
20pub trait GenericClient {
21 async fn query(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>>;
23
24 async fn query_one(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Row>;
26
27 async fn query_opt(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)])
29 -> Result<Option<Row>>;
30
31 async fn execute(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64>;
33
34 async fn simple_query(&mut self, sql: &str) -> Result<Vec<SimpleQueryMessage>>;
36}
37
38impl GenericClient for Connection {
39 async fn query(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>> {
40 Connection::query(self, sql, params).await
41 }
42
43 async fn query_one(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Row> {
44 Connection::query_one(self, sql, params).await
45 }
46
47 async fn query_opt(
48 &mut self,
49 sql: &str,
50 params: &[&(dyn ToSql + Sync)],
51 ) -> Result<Option<Row>> {
52 Connection::query_opt(self, sql, params).await
53 }
54
55 async fn execute(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64> {
56 Connection::execute(self, sql, params).await
57 }
58
59 async fn simple_query(&mut self, sql: &str) -> Result<Vec<SimpleQueryMessage>> {
60 Connection::simple_query(self, sql).await
61 }
62}
63
64impl GenericClient for crate::PooledConnection {
65 async fn query(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>> {
66 Connection::query(self, sql, params).await
67 }
68
69 async fn query_one(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<Row> {
70 Connection::query_one(self, sql, params).await
71 }
72
73 async fn query_opt(
74 &mut self,
75 sql: &str,
76 params: &[&(dyn ToSql + Sync)],
77 ) -> Result<Option<Row>> {
78 Connection::query_opt(self, sql, params).await
79 }
80
81 async fn execute(&mut self, sql: &str, params: &[&(dyn ToSql + Sync)]) -> Result<u64> {
82 Connection::execute(self, sql, params).await
83 }
84
85 async fn simple_query(&mut self, sql: &str) -> Result<Vec<SimpleQueryMessage>> {
86 Connection::simple_query(self, sql).await
87 }
88}