Struct dittolive_ditto::store::dql::QueryResultItem
source · pub struct QueryResultItem { /* private fields */ }
Expand description
Represents a single match of a DQL query, similar to a “row” in SQL terms. It’s a reference type serving as a “cursor”, allowing for efficient access of the underlying data in various formats.
The row is lazily materialized and kept in memory until it goes out of scope. To reduce the memory footprint, access the items using the provided iterator.
let cars: Vec<Car> = all_cars_query_result
.iter()
.map(|query_result_item| query_result_item.deserialize_value().unwrap())
.collect();
Implementations§
source§impl QueryResultItem
impl QueryResultItem
sourcepub fn value(&self) -> Arc<HashMap<Box<str>, Value>>
pub fn value(&self) -> Arc<HashMap<Box<str>, Value>>
Returns the content as a materialized object.
The item’s value is .materialize()
-ed on first access and
subsequently on each access after performing .dematerialize()
. Once
materialized, the value is kept in memory until explicitly
.dematerialize()
-ed or the item goes out of scope.
sourcepub fn is_materialized(&self) -> bool
pub fn is_materialized(&self) -> bool
Returns true
if value is currently held materialized in memory,
otherwise returns false
.
See Also
sourcepub fn materialize(&mut self)
pub fn materialize(&mut self)
Loads the CBOR representation of the item’s content, decodes it as a
dictionary so it can be accessed via .value()
. Keeps the dictionary in
memory until .dematerialize()
is called. No-op if value
is already
materialized.
sourcepub fn dematerialize(&mut self)
pub fn dematerialize(&mut self)
Releases the materialized value from memory. No-op if item is not materialized.
sourcepub fn cbor_data(&self) -> Vec<u8> ⓘ
pub fn cbor_data(&self) -> Vec<u8> ⓘ
Return the content of the item as a CBOR slice.
Important: The returned CBOR slice is not cached, make sure to call this method once and keep it for as long as needed.
sourcepub fn json_string(&self) -> String
pub fn json_string(&self) -> String
Return the content of the item as a JSON string.
Important: The returned JSON string is not cached, make sure to call this method once and keep it for as long as needed.
sourcepub fn deserialize_value<T: DeserializeOwned>(&self) -> Result<T, DittoError>
pub fn deserialize_value<T: DeserializeOwned>(&self) -> Result<T, DittoError>
Convenience around Self::cbor_data()
deserialize
-ing the value.
Important: The returned value is not cached, make sure to call this method once and keep it for as long as needed.