Expand description
This crate implements various CqlType derivatives for storing String values of up to (and including) 255 chars in a CQL database.
Will allocate 1020 bytes per value linked.
§Benchmarks
Benchmarks supplied below are fairly rudimentary (and rounded) and are there to give a rough idea of relative costs.
Full benchmark code can be found in github and can be run with
rustup run nightly cargo bench
, but please be aware that they will allocate ~102MB of disk space. The read_to_stream benchmarks also differ slightly from
other CqlType derivatives as they stream into a Vector, not an Array.
Operation | Database dimensions | Mean time (ns) |
---|---|---|
Single point read | 1 | 3 060 (+/- 200) |
Single point read | 4 | 15 800 (+/- 1 100) |
Single point write | 1 | 2 800 (+/- 300) |
Single point write | 4 | 15 400 (+/- 1 000) |
Stream read 1 point | 1 | 3 500 (+/- 300) |
Stream read 1 point | 4 | 15 500 (+/- 1 100) |
Stream read 50 000 points | 1 | 56 700 000 (+/- 800 000) |
Stream read 50 000 points | 4 | 56 400 000 (+/- 150 000) |
§Examples
The following creates a 1D database, writes 2 values to it, and then streams them into an array.
const N_VALUES_TO_READ: usize = 3;
let base_point = [1];
let value1 = "item one";
let value3 = "شماره ۳";
cql_db::create_db::<TinyText>(
DATABASE_LOCATION,
&[3]
);
cql_db::write_value::<TinyText>(
DATABASE_LOCATION,
&base_point,
TinyText::try_from(value1)?
)?;
cql_db::write_value::<TinyText>(
DATABASE_LOCATION,
&[base_point[0] + 2],
TinyText::try_from(value3)?
)?;
let mut result = Vec::with_capacity(N_VALUES_TO_READ);
let mut stream = Cursor::new(Vec::new());
cql_db::read_to_stream::<TinyText>(
DATABASE_LOCATION,
&mut stream,
&base_point,
N_VALUES_TO_READ as u64
)?;
stream.seek(SeekFrom::Start(0));
unpack_stream(&mut stream, N_VALUES_TO_READ, |_, value| {
result.push(value)
})?;
assert_eq!(result[0], TinyText::try_from(value1)?);
assert_eq!(result[1], TinyText::new());
assert_eq!(result[2], TinyText::try_from(value3)?);
Modules§
Structs§
- Tiny
Text - Tuple wrapping
String
for working withTinyText
values in a CQL database.
Functions§
- unpack_
stream - Unpacks
n_values
ofTinyText
from a stream, callingvalue_handler
with each value and it’s index.