cdrs_async/query/
query_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};
9
10/// Traits that provides methods for immediate query execution.
11#[async_trait]
12pub trait QueryExecutor: Send {
13  async fn query_with_params_tw<Q: ToString + Send>(
14    mut self: Pin<&mut Self>,
15    query: Q,
16    query_params: QueryParams,
17    with_tracing: bool,
18    with_warnings: bool,
19  ) -> error::Result<Frame>;
20
21  /// Executes a query with default parameters:
22  /// * TDB
23  async fn query<Q: ToString + Send>(mut self: Pin<&mut Self>, query: Q) -> error::Result<Frame> {
24    self.query_tw(query, false, false).await
25  }
26
27  /// Executes a query with ability to trace it and see warnings, and default parameters:
28  /// * TBD
29  async fn query_tw<Q: ToString + Send>(
30    mut self: Pin<&mut Self>,
31    query: Q,
32    with_tracing: bool,
33    with_warnings: bool,
34  ) -> error::Result<Frame> {
35    let query_params = QueryParamsBuilder::new().finalize();
36    self
37      .query_with_params_tw(query, query_params, with_tracing, with_warnings)
38      .await
39  }
40
41  /// Executes a query with bounded values (either with or without names).
42  async fn query_with_values<Q: ToString + Send, V: Into<QueryValues> + Send>(
43    mut self: Pin<&mut Self>,
44    query: Q,
45    values: V,
46  ) -> error::Result<Frame> {
47    self.query_with_values_tw(query, values, false, false).await
48  }
49
50  /// Executes a query with bounded values (either with or without names)
51  /// and ability to see warnings, trace a request and default parameters.
52  async fn query_with_values_tw<Q: ToString + Send, V: Into<QueryValues> + Send>(
53    mut self: Pin<&mut Self>,
54    query: Q,
55    values: V,
56    with_tracing: bool,
57    with_warnings: bool,
58  ) -> error::Result<Frame> {
59    let query_params_builder = QueryParamsBuilder::new();
60    let query_params = query_params_builder.values(values.into()).finalize();
61    self
62      .query_with_params_tw(query, query_params, with_tracing, with_warnings)
63      .await
64  }
65
66  /// Executes a query with query params without warnings and tracing.
67  async fn query_with_params<Q: ToString + Send>(
68    mut self: Pin<&mut Self>,
69    query: Q,
70    query_params: QueryParams,
71  ) -> error::Result<Frame> {
72    self
73      .query_with_params_tw(query, query_params, false, false)
74      .await
75  }
76}