-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathlib.rs
266 lines (239 loc) · 9.66 KB
/
lib.rs
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//! Async Rust driver for the [Scylla](https://scylladb.com) database written in Rust.
//! Although optimized for Scylla, the driver is also compatible with [Apache Cassandra®](https://cassandra.apache.org/).
//!
//! # Documentation book
//! The best source to learn about this driver is the [documentation book](https://rust-driver.docs.scylladb.com/).\
//! This page contains mainly API documentation
//!
//! # Other documentation
//! * [Documentation book](https://rust-driver.docs.scylladb.com/)
//! * [Examples](https://github.com/scylladb/scylla-rust-driver/tree/main/examples)
//! * [Scylla documentation](https://docs.scylladb.com)
//! * [Cassandra® documentation](https://cassandra.apache.org/doc/latest/)
//!
//! # Driver overview
//! ### Connecting
//! All driver activity revolves around the [Session](crate::client::session::Session)\
//! `Session` is created by specifying a few known nodes and connecting to them:
//!
//! ```rust,no_run
//! use scylla::client::session::Session;
//! use scylla::client::session_builder::SessionBuilder;
//! use std::error::Error;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! let session: Session = SessionBuilder::new()
//! .known_node("127.0.0.1:9042")
//! .known_node("1.2.3.4:9876")
//! .build()
//! .await?;
//!
//! Ok(())
//! }
//! ```
//! `Session` is usually created using the [SessionBuilder](crate::client::session_builder::SessionBuilder).\
//! All configuration options for a `Session` can be specified while building.
//!
//! ### Making queries
//! After successfully connecting to the cluster we can make queries.\
//! The driver supports multiple query types:
//! * [Simple](crate::client::session::Session::query_unpaged)
//! * [Simple paged](crate::client::session::Session::query_iter)
//! * [Prepared](crate::client::session::Session::execute_unpaged) (need to be [prepared](crate::client::session::Session::prepare) before use)
//! * [Prepared paged](crate::client::session::Session::execute_iter)
//! * [Batch](crate::client::session::Session::batch)
//!
//! To specify options for a single query create the query object and configure it:
//! * For simple: [`Statement`](crate::statement::unprepared::Statement)
//! * For prepared: [`PreparedStatement`](crate::statement::prepared::PreparedStatement)
//! * For batch: [`Batch`](crate::statement::batch::Batch)
//!
//! The easiest way to specify bound values in a query is using a tuple:
//! ```rust
//! # use scylla::client::session::Session;
//! # use std::error::Error;
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
//! // Insert an int and text into the table
//! session
//! .query_unpaged(
//! "INSERT INTO ks.tab (a, b) VALUES(?, ?)",
//! (2_i32, "some text")
//! )
//! .await?;
//! # Ok(())
//! # }
//! ```
//! But the driver will accept anything implementing the trait [SerializeRow].
//!
//! ### Receiving results
//! The easiest way to read rows returned by a query is to cast each row to a tuple of values:
//!
//! ```rust
//! # use scylla::client::session::Session;
//! # use std::error::Error;
//! # async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
//!
//! // Read rows containing an int and text
//! // Keep in mind that all results come in one response (no paging is done!),
//! // so the memory footprint and latency may be huge!
//! // To prevent that, use `Session::query_iter` or `Session::query_single_page`.
//! let query_rows = session
//! .query_unpaged("SELECT a, b FROM ks.tab", &[])
//! .await?
//! .into_rows_result()?;
//!
//! for row in query_rows.rows()? {
//! // Parse row as int and text \
//! let (int_val, text_val): (i32, &str) = row?;
//! }
//! # Ok(())
//! # }
//! ```
//! See the [book](https://rust-driver.docs.scylladb.com/stable/statements/result.html) for more receiving methods
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[doc(hidden)]
pub mod _macro_internal {
pub use scylla_cql::_macro_internal::*;
}
pub use scylla_cql::{DeserializeRow, DeserializeValue, SerializeRow, SerializeValue};
pub mod value {
// Every `pub` item is re-exported here, apart from `deser_cql_value`.
pub use scylla_cql::value::{
Counter, CqlDate, CqlDecimal, CqlDecimalBorrowed, CqlDuration, CqlTime, CqlTimestamp,
CqlTimeuuid, CqlValue, CqlVarint, CqlVarintBorrowed, MaybeUnset, Row, Unset, ValueOverflow,
};
}
pub mod frame {
pub use scylla_cql::frame::{frame_errors, Authenticator, Compression};
pub(crate) use scylla_cql::frame::{
parse_response_body_extensions, protocol_features, read_response_frame, request,
server_event_type, FrameParams, SerializedRequest,
};
pub mod types {
pub use scylla_cql::frame::types::{Consistency, SerialConsistency};
}
pub mod response {
pub(crate) use scylla_cql::frame::response::*;
pub mod result {
#[cfg(cpp_rust_unstable)]
pub use scylla_cql::frame::response::result::DeserializedMetadataAndRawRows;
pub(crate) use scylla_cql::frame::response::result::*;
pub use scylla_cql::frame::response::result::{
CollectionType, ColumnSpec, ColumnType, NativeType, PartitionKeyIndex, TableSpec,
UserDefinedType,
};
}
}
}
/// Serializing bound values of a query to be sent to the DB.
// Note: When editing comment on submodules here edit corresponding comments
// on scylla-cql modules too.
pub mod serialize {
pub use scylla_cql::serialize::SerializationError;
/// Contains the [BatchValues][batch::BatchValues] and [BatchValuesIterator][batch::BatchValuesIterator] trait and their
/// implementations.
pub mod batch {
// Main types
pub use scylla_cql::serialize::batch::{
BatchValues, BatchValuesFromIterator, BatchValuesIterator,
BatchValuesIteratorFromIterator, TupleValuesIter,
};
}
/// Contains the [SerializeRow][row::SerializeRow] trait and its implementations.
pub mod row {
// Main types
pub use scylla_cql::serialize::row::{RowSerializationContext, SerializeRow};
// Errors
pub use scylla_cql::serialize::row::{
BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind,
};
}
/// Contains the [SerializeValue][value::SerializeValue] trait and its implementations.
pub mod value {
// Main types
pub use scylla_cql::serialize::value::SerializeValue;
// Errors
pub use scylla_cql::serialize::value::{
BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, MapSerializationErrorKind, MapTypeCheckErrorKind,
SetOrListSerializationErrorKind, SetOrListTypeCheckErrorKind,
TupleSerializationErrorKind, TupleTypeCheckErrorKind, UdtSerializationErrorKind,
UdtTypeCheckErrorKind,
};
}
/// Contains types and traits used for safe serialization of values for a CQL statement.
pub mod writers {
pub use scylla_cql::serialize::writers::{
CellOverflowError, CellValueBuilder, CellWriter, RowWriter, WrittenCellProof,
};
}
}
/// Deserializing DB response containing CQL query results.
pub mod deserialize {
pub use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
/// Deserializing the whole query result contents.
pub mod result {
pub use scylla_cql::deserialize::result::TypedRowIterator;
}
/// Deserializing a row of the query result.
pub mod row {
pub use scylla_cql::deserialize::row::{
BuiltinDeserializationError, BuiltinDeserializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, ColumnIterator, DeserializeRow, RawColumn,
};
}
/// Deserializing a single CQL value from a column of the query result row.
pub mod value {
pub use scylla_cql::deserialize::value::{
BuiltinDeserializationError, BuiltinDeserializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, DeserializeValue, Emptiable, ListlikeIterator,
MapDeserializationErrorKind, MapIterator, MapTypeCheckErrorKind, MaybeEmpty,
SetOrListDeserializationErrorKind, SetOrListTypeCheckErrorKind,
TupleDeserializationErrorKind, TupleTypeCheckErrorKind, UdtIterator,
UdtTypeCheckErrorKind,
};
}
// Shorthands for better readability.
pub(crate) trait DeserializeOwnedRow:
for<'frame, 'metadata> row::DeserializeRow<'frame, 'metadata>
{
}
impl<T> DeserializeOwnedRow for T where
T: for<'frame, 'metadata> row::DeserializeRow<'frame, 'metadata>
{
}
}
pub mod authentication;
pub mod client;
#[cfg(feature = "unstable-cloud")]
pub mod cloud;
pub mod cluster;
pub mod errors;
mod network;
pub mod observability;
pub mod policies;
pub mod response;
pub mod routing;
pub mod statement;
pub(crate) mod utils;
#[cfg(test)]
pub(crate) use utils::test_utils;
#[cfg(feature = "unstable-testing")]
#[doc(hidden)]
pub mod internal_testing {
use scylla_cql::serialize::row::SerializedValues;
use crate::routing::partitioner::PartitionerName;
use crate::routing::Token;
use crate::statement::prepared::TokenCalculationError;
pub fn calculate_token_for_partition_key(
serialized_partition_key_values: &SerializedValues,
partitioner: &PartitionerName,
) -> Result<Token, TokenCalculationError> {
crate::routing::partitioner::calculate_token_for_partition_key(
serialized_partition_key_values,
partitioner,
)
}
}