Querying Data with DQL
-
Represents the result of executing a DQL query.
Note
More info such as metrics will be provided in the near future.
Declaration
Swift
public class DittoQueryResult
-
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) anddematerialize()
them right after use:let cars = allCarsQueryResult.items.map { item in // Pull out relevant data: let model = item.value["model"] as! String let 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 dictionary can be very cumbersome in Swift, especially if your data is deeply nested. Consider defining a struct describing the shape of your data, then decoding it via
jsonString()
:
See morestruct Car: Codable { model: String mileage: Int } let jsonData = item.jsonString().data(using: .utf8) try JSONDecoder().decode(Car.self, data: jsonData)
Declaration
Swift
public class DittoQueryResultItem