DittoQueryResultItem

class DittoQueryResultItem(val ffiDqlResult: SWIGTYPE_p_CDqlResult) : Closeable

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

Link copied to clipboard
fun DittoQueryResultItem(ffiDqlResult: SWIGTYPE_p_CDqlResult)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun cborData(): ByteArray

Returns the content of the item as CBOR data.

Link copied to clipboard
open override fun close()

Clean up result and release resources.

Link copied to clipboard
fun dematerialize()

Releases the materialized value from memory. No-op if item is not materialized.

Link copied to clipboard
fun jsonString(): String

Returns the content of the item as a JSON string.

Link copied to clipboard
fun materialize(): Map<String, Any>?

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.

Properties

Link copied to clipboard
val ffiDqlResult: SWIGTYPE_p_CDqlResult

CDqlResponse_t

Link copied to clipboard
val isMaterialized: Boolean

Returns true if value is currently held materialized in memory, otherwise returns false.

Link copied to clipboard
val value: Map<String, Any>

Returns the content as a materialized dictionary.