1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use bb8;
use tokio::sync::Mutex;
use async_trait::async_trait;
use crate::cluster::{GetCompressor, GetConnection, ResponseCache};
use crate::error;
use crate::frame::{Frame, IntoBytes};
use crate::query::{Query, QueryParams, QueryParamsBuilder, QueryValues};
use crate::transport::CDRSTransport;
use super::utils::{prepare_flags, send_frame};
#[async_trait]
pub trait QueryExecutor<
T: CDRSTransport + Unpin + 'static,
M: bb8::ManageConnection<Connection = Mutex<T>, Error = error::Error> + Sized,
>: GetConnection<T, M> + GetCompressor<'static> + ResponseCache + Sync
{
async fn query_with_params_tw<Q: ToString + Send>(
&self,
query: Q,
query_params: QueryParams,
with_tracing: bool,
with_warnings: bool,
) -> error::Result<Frame>
where
Self: Sized,
{
let query = Query {
query: query.to_string(),
params: query_params,
};
let flags = prepare_flags(with_tracing, with_warnings);
let query_frame = Frame::new_query(query, flags);
send_frame(self, query_frame.into_cbytes(), query_frame.stream).await
}
async fn query<Q: ToString + Send>(&self, query: Q) -> error::Result<Frame>
where
Self: Sized,
{
self.query_tw(query, false, false).await
}
async fn query_tw<Q: ToString + Send>(
&self,
query: Q,
with_tracing: bool,
with_warnings: bool,
) -> error::Result<Frame>
where
Self: Sized,
{
let query_params = QueryParamsBuilder::new().finalize();
self.query_with_params_tw(query, query_params, with_tracing, with_warnings).await
}
async fn query_with_values<Q: ToString + Send, V: Into<QueryValues> + Send>(
&self,
query: Q,
values: V,
) -> error::Result<Frame>
where
Self: Sized,
{
self.query_with_values_tw(query, values, false, false).await
}
async fn query_with_values_tw<Q: ToString + Send, V: Into<QueryValues> + Send>(
&self,
query: Q,
values: V,
with_tracing: bool,
with_warnings: bool,
) -> error::Result<Frame>
where
Self: Sized,
{
let query_params_builder = QueryParamsBuilder::new();
let query_params = query_params_builder.values(values.into()).finalize();
self.query_with_params_tw(query, query_params, with_tracing, with_warnings).await
}
async fn query_with_params<Q: ToString + Send>(
&self,
query: Q,
query_params: QueryParams,
) -> error::Result<Frame>
where
Self: Sized,
{
self.query_with_params_tw(query, query_params, false, false).await
}
}