PersistableRecord

public protocol PersistableRecord : MutablePersistableRecord

Types that adopt PersistableRecord can be inserted, updated, and deleted.

Unlike MutablePersistableRecord, the insert(_:) and save(_:) methods are not mutating methods.

  • didInsert(with:for:) Default implementation

    Notifies the record that it was successfully inserted.

    Do not call this method directly: it is called for you, in a protected dispatch queue, with the inserted RowID and the eventual INTEGER PRIMARY KEY column name.

    This method is optional: the default implementation does nothing.

    If you need a mutating variant of this method, adopt the MutablePersistableRecord protocol instead.

    Default Implementation

    Notifies the record that it was successfully inserted.

    The default implementation does nothing.

    Declaration

    Swift

    func didInsert(with rowID: Int64, for column: String?)

    Parameters

    rowID

    The inserted rowID.

    column

    The name of the eventual INTEGER PRIMARY KEY column.

  • insert(_:) Default implementation

    Executes an INSERT statement.

    This method is guaranteed to have inserted a row in the database if it returns without error.

    Upon successful insertion, the didInsert(with:for:) method is called with the inserted RowID and the eventual INTEGER PRIMARY KEY column name.

    This method has a default implementation, so your adopting types don’t have to implement it. Yet your types can provide their own implementation of insert(). In their implementation, it is recommended that they invoke the performInsert() method.

    Throws

    A DatabaseError whenever an SQLite error occurs.

    Default Implementation

    Executes an INSERT statement.

    The default implementation for insert() invokes performInsert().

    Declaration

    Swift

    func insert(_ db: Database) throws

    Parameters

    db

    A database connection.

  • save(_:) Default implementation

    Executes an INSERT or an UPDATE statement so that self is saved in the database.

    If the receiver has a non-nil primary key and a matching row in the database, this method performs an update.

    Otherwise, performs an insert.

    This method is guaranteed to have inserted or updated a row in the database if it returns without error.

    This method has a default implementation, so your adopting types don’t have to implement it. Yet your types can provide their own implementation of save(). In their implementation, it is recommended that they invoke the performSave() method.

    Throws

    A DatabaseError whenever an SQLite error occurs, or errors thrown by update().

    Default Implementation

    Executes an INSERT or an UPDATE statement so that self is saved in the database.

    The default implementation for save() invokes performSave().

    Declaration

    Swift

    func save(_ db: Database) throws

    Parameters

    db

    A database connection.

Immutable CRUD Internals

  • performInsert(_:) Extension method

    Don’t invoke this method directly: it is an internal method for types that adopt PersistableRecord.

    performInsert() provides the default implementation for insert(). Types that adopt PersistableRecord can invoke performInsert() in their implementation of insert(). They should not provide their own implementation of performInsert().

    Declaration

    Swift

    public func performInsert(_ db: Database) throws
  • performSave(_:) Extension method

    Don’t invoke this method directly: it is an internal method for types that adopt PersistableRecord.

    performSave() provides the default implementation for save(). Types that adopt PersistableRecord can invoke performSave() in their implementation of save(). They should not provide their own implementation of performSave().

    This default implementation forwards the job to update or insert.

    Declaration

    Swift

    public func performSave(_ db: Database) throws