Record.updateChanges(_:)

This commit is contained in:
Gwendal Roué committed 2017-09-06 08:36:13 +02:00
1 parent da51e81e38
commit f4f72ebb43
2 files changed
+23

No files matched your search

+22
View File
@@ -301,6 +301,28 @@ open class Record : RowConvertible, TableMapping, Persistable {
referenceRow = Row(dao.persistenceContainer)
}
/// If the record has been changed, executes an UPDATE statement so that
/// those changes and only those changes are saved in the database.
///
/// On success, this method sets the *hasPersistentChangedValues* flag
/// to false.
///
/// This method is guaranteed to have saved the eventual changes in the
/// database if it returns without error.
///
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.recordNotFound is thrown if the primary key does not
/// match any row in the database and record could not be updated.
final public func updateChanges(_ db: Database) throws {
let changedColumns = Set(persistentChangedValues.keys)
guard !changedColumns.isEmpty else {
return
}
try update(db, columns: changedColumns)
}
/// Executes an INSERT or an UPDATE statement so that `self` is saved in
/// the database.
///
+1
View File
@@ -19,6 +19,7 @@ GRDB 2.0
- [ ] check performance improvements
- [ ] document
- [ ] Test new adoption of StatementColumnConvertible by Data. Add support for NSData if possible/needed.
- [ ] Document Record.updateChanges(_:)
Not sure