Ditto 5.0.0
Loading...
Searching...
No Matches
DittoSDK.Store.DittoQueryResultItem Class Reference

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. More...

Inheritance diagram for DittoSDK.Store.DittoQueryResultItem:
DittoSDK.Internal.Drop

Public Member Functions

void Materialize ()
 Loads the CBOR representation of the item's content, decodes it as a dictionary so it can be accessed via DittoQueryResultItem.Value. Keeps the dictionary in memory until DittoQueryResultItem.Dematerialize() is called. No-op if DittoQueryResultItem.Value is already materialized.
void Dematerialize ()
 Releases the materialized value from memory. No-op if item is not materialized.

See also
Dispose

For completly disposing of the instance..

CBORObject CborData ()
 Returns the content of the item as CBOR data.
string JsonString ()
 Returns the content of the item as a JSON string.
Public Member Functions inherited from DittoSDK.Internal.Drop
void Dispose ()
 Suppresses finalization and initiates custom disposal logic.

Protected Member Functions

override unsafe void Dispose (bool disposing)
Protected Member Functions inherited from DittoSDK.Internal.Drop
void Dispose (bool disposing)
 Overload for types to dispose of resources, regardless of whether the type is being disposed or finalized. Note that finalization occurs on a dedicated thread.

Properties

Dictionary< string, object > Value [get]
 Gets the content as a materialized dictionary.
bool IsMaterialized [get]
 Gets a value indicating whether the item is currently held materialized in memory or not.
Properties inherited from DittoSDK.Internal.Drop
bool IsDisposed [get]

Detailed 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 DittoQueryResultItem.Value property is lazily materialized and kept in memory until the instance is garbage collected. To reduce the memory footprint, structure your code such that items can be processed as a stream, i.e. one by one (or in batches) and DittoQueryResultItem.Dematerialize() them right after use:

var cars = allCarsQueryResult.Items.Select((item) =>
{
var model = item.Value["model"] as string;
var mileage = item.Value["mileage"];
item.Dematerialize();
item.Dispose(); //also dispose of the item if it's not intended for further use.
return new Car(model, mileage);
});

You can also consider taking the JSON string of the item and Deserialize it:

var cars = allCarsQueryResult.Items.Select((item) =>
{
var itemJsonString = item.JsonString();
item.Dispose();
return JsonSerializer.Deserialize&lt;Car&gt;(itemJsonString);
});

Member Function Documentation

◆ CborData()

CBORObject DittoSDK.Store.DittoQueryResultItem.CborData ( )
inline

Returns the content of the item as CBOR data.

Note
Important: The returned CBOR data is not cached, make sure to call this method once and keep the returned data for as long as needed.
Returns
The CBOR representation of the item.

◆ JsonString()

string DittoSDK.Store.DittoQueryResultItem.JsonString ( )
inline

Returns the content of the item as a JSON string.

Note
Important: The returned JSON string is not cached, make sure to call this method once and keep the returned data for as long as needed.
Returns
The JSON string representation of the item.

Property Documentation

◆ IsMaterialized

bool DittoSDK.Store.DittoQueryResultItem.IsMaterialized
get

Gets a value indicating whether the item is currently held materialized in memory or not.

See also
DittoQueryResultItem.Materialize(), DittoQueryResultItem.Dematerialize()

◆ Value

Dictionary<string, object> DittoSDK.Store.DittoQueryResultItem.Value
get

Gets the content as a materialized dictionary.

The item's value is DittoQueryResultItem.Materialize() on first access and subsequently on each access after performing DittoQueryResultItem.Dematerialize(). Once materialized, the value is kept in memory until DittoQueryResultItem.Dematerialize() is explicitly called or the item goes out of scope.