DataStoreBaseBehavior

public protocol DataStoreBaseBehavior
  • Saves the model to storage. If sync is enabled, also initiates a sync of the mutation to the remote API

    Declaration

    Swift

    func save<M: Model>(_ model: M,
                        where condition: QueryPredicate?,
                        completion: @escaping DataStoreCallback<M>)
  • Declaration

    Swift

    func query<M: Model>(_ modelType: M.Type,
                         byId id: String,
                         completion: DataStoreCallback<M?>)
  • Declaration

    Swift

    func query<M: Model>(_ modelType: M.Type,
                         byIdentifier id: String,
                         completion: DataStoreCallback<M?>) where M: ModelIdentifiable,
                                                                  M.IdentifierFormat == ModelIdentifierFormat.Default
  • Declaration

    Swift

    func query<M: Model>(_ modelType: M.Type,
                         byIdentifier id: ModelIdentifier<M, M.IdentifierFormat>,
                         completion: DataStoreCallback<M?>) where M: ModelIdentifiable
  • Declaration

    Swift

    func query<M: Model>(_ modelType: M.Type,
                         where predicate: QueryPredicate?,
                         sort sortInput: QuerySortInput?,
                         paginate paginationInput: QueryPaginationInput?,
                         completion: DataStoreCallback<[M]>)
  • Declaration

    Swift

    func delete<M: Model>(_ model: M,
                          where predicate: QueryPredicate?,
                          completion: @escaping DataStoreCallback<Void>)
  • Declaration

    Swift

    func delete<M: Model>(_ modelType: M.Type,
                          withId id: String,
                          where predicate: QueryPredicate?,
                          completion: @escaping DataStoreCallback<Void>)
  • Declaration

    Swift

    func delete<M: Model>(_ modelType: M.Type,
                          withIdentifier id: String,
                          where predicate: QueryPredicate?,
                          completion: @escaping DataStoreCallback<Void>) where M: ModelIdentifiable,
                                                                               M.IdentifierFormat == ModelIdentifierFormat.Default
  • Declaration

    Swift

    func delete<M: Model>(_ modelType: M.Type,
                          withIdentifier id: ModelIdentifier<M, M.IdentifierFormat>,
                          where predicate: QueryPredicate?,
                          completion: @escaping DataStoreCallback<Void>) where M: ModelIdentifiable
  • Declaration

    Swift

    func delete<M: Model>(_ modelType: M.Type,
                           where predicate: QueryPredicate,
                           completion: @escaping DataStoreCallback<Void>)
  • Synchronization starts automatically whenever you run any DataStore operation (query(), save(), delete()) however, you can explicitly begin the process with DatasStore.start()

    Declaration

    Swift

    func start(completion: @escaping DataStoreCallback<Void>)

    Parameters

    completion

    callback to be invoked on success or failure

  • To stop the DataStore sync process, you can use DataStore.stop(). This ensures the real time subscription connection is closed when your app is no longer interested in updates, such as when you application is closed. This can also be used to modify DataStore sync expressions at runtime by calling stop(), then start() to force your sync expressions to be re-evaluated.

    Declaration

    Swift

    func stop(completion: @escaping DataStoreCallback<Void>)

    Parameters

    completion

    callback to be invoked on success or failure

  • To clear local data from DataStore, use the clear method.

    Declaration

    Swift

    func clear(completion: @escaping DataStoreCallback<Void>)

    Parameters

    completion

    callback to be invoked on success or failure

  • clear() Extension method

    Clears the local data store

    Note

    If sync is enabled, this method does not clear the remote store

    Declaration

    Swift

    func clear() -> DataStorePublisher<Void>

    Return Value

    A DataStorePublisher with the results of the operation

  • delete(_:withId:where:) Extension method

    Deletes the model with the specified ID from the DataStore. If sync is enabled, this will delete the model from the remote store as well.

    Declaration

    Swift

    @available(*, deprecated, message: "Use delete(:withIdentifier:where:﹚")
    func delete<M: Model>(
        _ modelType: M.Type,
        withId id: String,
        where predicate: QueryPredicate? = nil
    ) -> DataStorePublisher<Void>

    Parameters

    modelType

    The type of the model to delete

    id

    The ID of the model to delete

    Return Value

    A DataStorePublisher with the results of the operation

  • Deletes the model with the specified identifier from the DataStore. If sync is enabled, this will delete the model from the remote store as well.

    Declaration

    Swift

    func delete<M: Model>(
        _ modelType: M.Type,
        withIdentifier identifier: String,
        where predicate: QueryPredicate? = nil
    )  -> DataStorePublisher<Void> where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default

    Parameters

    modelType

    The type of the model to delete

    identifier

    The identifier of the model to delete

    Return Value

    A DataStorePublisher with the results of the operation

  • Deletes the model with the specified identifier from the DataStore. If sync is enabled, this will delete the model from the remote store as well.

    Declaration

    Swift

    func delete<M: Model>(
        _ modelType: M.Type,
        withIdentifier identifier: ModelIdentifier<M, M.IdentifierFormat>,
        where predicate: QueryPredicate? = nil
    )  -> DataStorePublisher<Void> where M: ModelIdentifiable

    Parameters

    modelType

    The type of the model to delete

    identifier

    The identifier of the model to delete

    Return Value

    A DataStorePublisher with the results of the operation

  • delete(_:where:) Extension method

    Deletes models matching the predicate from the DataStore. If sync is enabled, this will delete the model from the remote store as well.

    Declaration

    Swift

    func delete<M: Model>(
        _ modelType: M.Type,
        where predicate: QueryPredicate
    ) -> DataStorePublisher<Void>

    Parameters

    modelType

    The type of the model to delete

    predicate

    The models that match this predicate to be deleted

    Return Value

    A DataStorePublisher with the results of the operation

  • delete(_:where:) Extension method

    Deletes the specified model instance from the DataStore. If sync is enabled, this will delete the model from the remote store as well.

    Declaration

    Swift

    func delete<M: Model>(
        _ model: M,
        where predicate: QueryPredicate? = nil
    ) -> DataStorePublisher<Void>

    Parameters

    model

    The model instance to delete

    predicate

    The predicate used to filter whether the delete will be executed or not

    Return Value

    A DataStorePublisher with the results of the operation

  • query(_:byId:) Extension method

    Queries for a specific model instance by id

    Declaration

    Swift

    @available(*, deprecated, message: "Use query(:byIdentifier:﹚")
    func query<M: Model>(
        _ modelType: M.Type,
        byId id: String
    ) -> DataStorePublisher<M?>

    Parameters

    modelType

    The type of the model to query

    id

    The ID of the model to query

    Return Value

    A DataStorePublisher with the results of the operation

  • query(_:byIdentifier:) Extension method

    Queries for a specific model instance by id

    Declaration

    Swift

    func query<M: Model>(
        _ modelType: M.Type,
        byIdentifier identifier: String
    ) -> DataStorePublisher<M?> where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default

    Parameters

    modelType

    The type of the model to query

    id

    The ID of the model to query

    Return Value

    A DataStorePublisher with the results of the operation

  • query(_:byIdentifier:) Extension method

    Queries for a specific model instance by id

    Declaration

    Swift

    func query<M: Model>(
        _ modelType: M.Type,
        byIdentifier identifier: ModelIdentifier<M, M.IdentifierFormat>
    ) -> DataStorePublisher<M?> where M: ModelIdentifiable

    Parameters

    modelType

    The type of the model to query

    id

    The ID of the model to query

    Return Value

    A DataStorePublisher with the results of the operation

  • Queries for any model instances that match the specified predicate

    Declaration

    Swift

    func query<M: Model>(
        _ modelType: M.Type,
        where predicate: QueryPredicate? = nil,
        sort sortInput: QuerySortInput? = nil,
        paginate paginationInput: QueryPaginationInput? = nil
    ) -> DataStorePublisher<[M]>

    Parameters

    modelType

    The type of the model to query

    predicate

    The predicate for filtering results

    sort

    Describes how to sort the query results

    paginate

    Describes how to paginate the query results

    Return Value

    A DataStorePublisher with the results of the operation

  • save(_:where:) Extension method

    Saves the model to storage. If sync is enabled, also initiates a sync of the mutation to the remote API.

    Declaration

    Swift

    func save<M: Model>(
        _ model: M,
        where condition: QueryPredicate? = nil
    ) -> DataStorePublisher<M>

    Parameters

    model

    The model instance to save. The model can be new or existing, and the DataStore will either create or update as appropriate

    condition

    The condition under which to perform the save

    Return Value

    A DataStorePublisher with the results of the operation