Database

protocol Database

Protocol used to define the Database, configurations and operations.

  • Configure database for the current instance.

    Note

    Should called only once.

    Declaration

    Swift

    func configure()
  • Obtains a new instance of type T.

    Declaration

    Swift

    func newObject<T>() -> T where T : Model
  • Deletes an object from the Database. Once the object is deleted it is considered invalidated.

    Declaration

    Swift

    func deleteObject<T>(_ object: T) where T : Model

    Parameters

    object

    The object to be deleted.

  • Obtains the instance of type T corresponding the Unique ID passed by argument.

    Declaration

    Swift

    func object<T>(_ type: T.Type, uniqueID id: String) -> T? where T : Model

    Parameters

    type

    The type of the object to be found and returned.

    id

    The Unique ID of the object.

    Return Value

    The object that was found or nil if it wasn’t found.

  • Obtains the instance of type T corresponding the Primary Key passed by argument.

    Declaration

    Swift

    func object<T>(_ type: T.Type, primaryKey pkValue: T.PrimaryKeyType) throws -> T? where T : Model

    Parameters

    type

    The type of the object to be found and returned.

    primaryKey

    The Primary Key of the object.

    Return Value

    The object that was found or nil if it wasn’t found.

  • Create a new query for model of type T.

    Declaration

    Swift

    func query<T>(_ entity: T.Type) -> DatabaseQuery<T> where T : Model

    Parameters

    type

    The type of the object to be searched.

    Return Value

    The query instance of type DatabaseQuery.

  • Adds a notification handler for changes made to this Database, and returns a notification token.

    Note

    You must retain the returned token for as long as you want updates to be sent to the block. To stop receiving updates, call invalidate() on the token.

    Declaration

    Swift

    func observe(handler: @escaping DatabaseObserverToken.Handler) -> DatabaseObserverToken

    Parameters

    block

    A block which is called to process notifications.

    Return Value

    A token which must be held for as long as you wish to continue receiving change notifications.