Querying Data with DQL

  • Defines the interface for executing DQL queries. Implemented by DittoStore and DittoTransaction.

    See more

    Declaration

    Swift

    public protocol DittoQueryExecuting
  • Represents the result of executing a DQL query.

    Note

    More info such as metrics will be provided in the near future.

    See more

    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) and dematerialize() 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():

    struct Car: Codable {
        model: String
        mileage: Int
    }
    
    let jsonData = item.jsonData()
    try JSONDecoder().decode(Car.self, data: jsonData)
    
    See more

    Declaration

    Swift

    public class DittoQueryResultItem
  • Represents a transaction in the Ditto store.

    A DittoTransaction is 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 also

    DittoStore.transaction(_:hint:with:)
    See more

    Declaration

    Swift

    public class DittoTransaction
    extension DittoTransaction: DittoQueryExecuting
  • Encapsulates information about a transaction.

    Declaration

    Swift

    public struct DittoTransactionInfo
    extension DittoTransactionInfo: Hashable
    extension DittoTransactionInfo: Equatable
    extension DittoTransactionInfo: Codable
  • Represents an action that completes a transaction, by either committing it or rolling it back.

    See more

    Declaration

    Swift

    public enum DittoTransactionCompletionAction
    extension DittoTransactionCompletionAction: Equatable