Querying Data with DQL
-
Defines the interface for executing DQL queries. Implemented by
See moreDittoStoreandDittoTransaction.Declaration
Swift
public protocol DittoQueryExecuting -
Represents the result of executing a DQL query.
See moreNote
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
valueproperty 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
jsonData():
See morestruct Car: Codable { model: String mileage: Int } let jsonData = item.jsonData() try JSONDecoder().decode(Car.self, data: jsonData)Declaration
Swift
public class DittoQueryResultItem -
Represents a transaction in the Ditto store.
A
DittoTransactionis used to group multiple operations into a single atomic unit. This ensures that either all operations within the transaction are applied, or none of them are, maintaining the integrity of the data.Please consult the documentation of
DittoStore.transaction(_:hint:with:)for more information on how to create and use transactions. For a complete guide on transactions, please refer to the Ditto documentation.See moreSee also
DittoStore.transaction(_:hint:with:)Declaration
-
Encapsulates information about a transaction.
Declaration
Swift
public struct DittoTransactionInfoextension DittoTransactionInfo: Hashableextension DittoTransactionInfo: Equatableextension DittoTransactionInfo: Codable -
Represents an action that completes a transaction, by either committing it or rolling it back.
See moreDeclaration
Swift
public enum DittoTransactionCompletionActionextension DittoTransactionCompletionAction: Equatable
Querying Data with DQL Reference