cdrs_async/query/
exec_executor.rs

1use std::pin::Pin;
2
3use async_trait::async_trait;
4use cassandra_proto::{
5  error,
6  frame::Frame,
7  query::{QueryParams, QueryParamsBuilder, QueryValues},
8  types::CBytesShort,
9};
10
11/// Prepared query ID.
12pub type PreparedQuery = CBytesShort;
13
14/// Traits that provides methods for prepared query execution.
15#[async_trait]
16pub trait ExecExecutor: Send {
17  async fn exec_with_params_tw(
18    mut self: Pin<&mut Self>,
19    prepared: &PreparedQuery,
20    query_parameters: QueryParams,
21    with_tracing: bool,
22    with_warnings: bool,
23  ) -> error::Result<Frame>;
24
25  async fn exec_with_params(
26    mut self: Pin<&mut Self>,
27    prepared: &PreparedQuery,
28    query_parameters: QueryParams,
29  ) -> error::Result<Frame> {
30    self
31      .exec_with_params_tw(prepared, query_parameters, false, false)
32      .await
33  }
34
35  async fn exec_with_values_tw<V: Into<QueryValues> + Send>(
36    mut self: Pin<&mut Self>,
37    prepared: &PreparedQuery,
38    values: V,
39    with_tracing: bool,
40    with_warnings: bool,
41  ) -> error::Result<Frame> {
42    let query_params_builder = QueryParamsBuilder::new();
43    let query_params = query_params_builder.values(values.into()).finalize();
44    self
45      .exec_with_params_tw(prepared, query_params, with_tracing, with_warnings)
46      .await
47  }
48
49  async fn exec_with_values<V: Into<QueryValues> + Send>(
50    mut self: Pin<&mut Self>,
51    prepared: &PreparedQuery,
52    values: V,
53  ) -> error::Result<Frame> {
54    self
55      .exec_with_values_tw(prepared, values, false, false)
56      .await
57  }
58
59  async fn exec_tw(
60    mut self: Pin<&mut Self>,
61    prepared: &PreparedQuery,
62    with_tracing: bool,
63    with_warnings: bool,
64  ) -> error::Result<Frame> {
65    let query_params = QueryParamsBuilder::new().finalize();
66    self
67      .exec_with_params_tw(prepared, query_params, with_tracing, with_warnings)
68      .await
69  }
70
71  async fn exec(mut self: Pin<&mut Self>, prepared: &PreparedQuery) -> error::Result<Frame> {
72    self.exec_tw(prepared, false, false).await
73  }
74}