Ditto Query Result Item
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 value property is lazily materialized and kept in memory until it goes out of scope. 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 dematerialize them right after use:
val cars = allCarsQueryResult.items.map { item ->
// Pull out relevant data:
val model = item.value["model"] as String
val mileage = item.value["mileage"] as Int
// Prune to free memory:
item.dematerialize()
// Use the pulled out data:
return Car(model = model, mileage = mileage)
}
Pulling the contents out of a map can be cumbersome in Kotlin, especially if your data is deeply nested. Consider defining a data class describing the shape of your data, then decoding jsonString using Kotlin Serialization:
@Serializable
data class Car(
val model: String
val mileage: Int
)
val jsonString = item.jsonString()
val car = Json {
isLenient = true
ignoreUnknownKeys = true
allowStructuredMapKeys = true
}.decodeFromString<Car>(jsonString)
Since
4.5.0
Constructors
Types
Functions
Releases the materialized value from memory. No-op if item is not materialized.
Returns the content of the item as a JSON string.
Loads the CBOR representation of the item's content, decodes it into a Map so it can be accessed via value. Keeps the Map in memory until dematerialize is called. No-op if value
is already materialized.