1+ //! CQL protocol-level representation of a `QUERY` request.
2+
13use std:: { borrow:: Cow , num:: TryFromIntError , ops:: ControlFlow , sync:: Arc } ;
24
35use crate :: frame:: { frame_errors:: CqlRequestSerializationError , types:: SerialConsistency } ;
@@ -28,9 +30,14 @@ const ALL_FLAGS: u8 = FLAG_VALUES
2830 | FLAG_WITH_DEFAULT_TIMESTAMP
2931 | FLAG_WITH_NAMES_FOR_VALUES ;
3032
33+ /// CQL protocol-level representation of an `QUERY` request,
34+ /// used to execute a single unprepared statement.
3135#[ cfg_attr( test, derive( Debug , PartialEq , Eq ) ) ]
3236pub struct Query < ' q > {
37+ /// CQL statement string to execute.
3338 pub contents : Cow < ' q , str > ,
39+
40+ /// Various parameters controlling the execution of the statement.
3441 pub parameters : QueryParameters < ' q > ,
3542}
3643
@@ -59,14 +66,36 @@ impl DeserializableRequest for Query<'_> {
5966 }
6067}
6168
69+ /// Various parameters controlling the execution of the statement.
6270#[ cfg_attr( test, derive( Debug , PartialEq , Eq ) ) ]
6371pub struct QueryParameters < ' a > {
72+ /// Consistency level for the query.
6473 pub consistency : types:: Consistency ,
74+
75+ /// Serial consistency level for the query, if specified.
6576 pub serial_consistency : Option < types:: SerialConsistency > ,
77+
78+ /// Client-side-assigned timestamp for the query, if specified.
6679 pub timestamp : Option < i64 > ,
80+
81+ /// Maximum number of rows to return for the query, if specified.
82+ /// If not specified, the server will not page the result, and instead return all rows
83+ /// in a single response. This is not recommended for large result sets, as it puts
84+ /// a lot of pressure on the server and network, as well as brings high memory usage
85+ /// on both client and server sides.
6786 pub page_size : Option < i32 > ,
87+
88+ /// Paging state for the query, used to resume fetching results from a previous query.
89+ /// If empty paging state is provided, the query will start from the beginning.
6890 pub paging_state : PagingState ,
91+
92+ /// Whether to skip metadata for the values in the result set.
93+ /// This is an optimisation that can be used when the client does not need
94+ /// the metadata for the values, because it has already been fetched upon
95+ /// preparing the statement.
6996 pub skip_metadata : bool ,
97+
98+ /// Values bound to the statements.
7099 pub values : Cow < ' a , SerializedValues > ,
71100}
72101
@@ -85,6 +114,7 @@ impl Default for QueryParameters<'_> {
85114}
86115
87116impl QueryParameters < ' _ > {
117+ /// Serializes the parameters into the provided buffer.
88118 pub fn serialize (
89119 & self ,
90120 buf : & mut impl BufMut ,
@@ -145,6 +175,7 @@ impl QueryParameters<'_> {
145175}
146176
147177impl QueryParameters < ' _ > {
178+ /// Deserializes the parameters from the provided buffer.
148179 pub fn deserialize ( buf : & mut & [ u8 ] ) -> Result < Self , RequestDeserializationError > {
149180 let consistency = types:: read_consistency ( buf) ?;
150181
@@ -209,9 +240,19 @@ impl QueryParameters<'_> {
209240 }
210241}
211242
243+ /// A response containing the paging state of a paged query,
244+ /// i.e. whether there are more pages to fetch or not, and if so,
245+ /// what is the state to use for resuming the query from the next page.
212246#[ derive( Debug , Clone ) ]
213247pub enum PagingStateResponse {
214- HasMorePages { state : PagingState } ,
248+ /// Indicates that there are more pages to fetch, and provides the
249+ /// [PagingState] to use for resuming the query from the next page.
250+ HasMorePages {
251+ /// The paging state to use for resuming the query from the next page.
252+ state : PagingState ,
253+ } ,
254+
255+ /// Indicates that there are no more pages to fetch, and the query has finished.
215256 NoMorePages ,
216257}
217258
0 commit comments