Partial update WIP: documentation

This commit is contained in:
Gwendal Roué committed 2016-07-28 09:05:46 +02:00
1 parent 176a23fe97
commit df7791a3e7
5 files changed
+65 -28

No files matched your search

+28
View File
@@ -6,8 +6,36 @@ Release Notes
**New**
- `Database.indexes(on:)` returns the indexes defined on a database table
- `Database.table(_:hasUniqueKey:)` returns true if a sequence of columns uniquely identifies a row, that is to say if the columns are the primary key, or if there is a unique index on them.
- MutablePersistable types, including Record subclasses, support partial updates:
```swift
try person.update(db) // Full update
try person.update(db, columns: ["age"]) // Only updates the age column
```
**Breaking Changes**
- MutablePersistable `update` and `performUpdate` methods have changed their signature:
```diff
protocol MutablePersistable : TableMapping {
-func update(db: Database) throws
+func update(db: Database, columns: Set<String>) throws
}
extension MutablePersistable {
func update(db: Database) throws
+func update(db: Database, columns: Set<String>) throws
+func update<S: SequenceType where S.Generator.Element == SQLColumn>(db: Database, columns: S) throws
+func update<S: SequenceType where S.Generator.Element == String>(db: Database, columns: S) throws
-func performUpdate(db: Database) throws
+func performUpdate(db: Database, columns: Set<String>) throws
}
```
## 0.76.0
+27 -17
View File
@@ -115,9 +115,8 @@ public protocol MutablePersistable : TableMapping {
/// implementation of update(). In their implementation, it is recommended
/// that they invoke the performUpdate() method.
///
/// TODO: columns
///
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
@@ -189,36 +188,43 @@ public extension MutablePersistable {
/// Executes an UPDATE statement.
///
/// TODO: columns
///
/// The default implementation for update() invokes performUpdate().
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
func update(db: Database, columns: Set<String>) throws {
try performUpdate(db, columns: columns)
}
/// Executes an UPDATE statement.
///
/// TODO: columns
///
/// The default implementation for update() invokes performUpdate().
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
func update<S: SequenceType where S.Generator.Element == SQLColumn>(db: Database, columns: S) throws {
try update(db, columns: Set(columns.map { $0.name }))
}
/// Executes an UPDATE statement.
///
/// TODO: columns
///
/// The default implementation for update() invokes performUpdate().
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
func update<S: SequenceType where S.Generator.Element == String>(db: Database, columns: S) throws {
try update(db, columns: Set(columns))
}
/// Executes an UPDATE statement.
/// Executes an UPDATE statement that updates all table columns.
///
/// TODO: columns
///
/// The default implementation for update() invokes performUpdate().
/// - parameter db: A database connection.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
func update(db: Database) throws {
let databaseTableName = self.dynamicType.databaseTableName()
let columns = try db.columns(in: databaseTableName)
@@ -281,12 +287,16 @@ public extension MutablePersistable {
/// Don't invoke this method directly: it is an internal method for types
/// that adopt MutablePersistable.
///
/// TODO: columns
///
/// performUpdate() provides the default implementation for update(). Types
/// that adopt MutablePersistable can invoke performUpdate() in their
/// implementation of update(). They should not provide their own
/// implementation of performUpdate().
///
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
func performUpdate(db: Database, columns: Set<String>) throws {
try DataMapper(db, self).updateStatement(columns: columns).execute()
if db.changesCount == 0 {
+3 -4
View File
@@ -249,12 +249,11 @@ public class Record : RowConvertible, TableMapping, Persistable {
/// This method is guaranteed to have updated a row in the database if it
/// returns without error.
///
/// TODO: columns
///
/// - parameter db: A database connection.
/// - parameter columns: The columns to update.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
/// PersistenceError.NotFound is thrown if the primary key does not match
/// any row in the database and record could not be updated.
/// PersistenceError.NotFound is thrown if the primary key does not
/// match any row in the database.
public func update(db: Database, columns: Set<String>) throws {
// The simplest code would be:
//
+6 -7
View File
@@ -1860,14 +1860,13 @@ paris.id // some value
[Record](#record-class) subclasses and types that adopt [Persistable](#persistable-protocol) are given default implementations for methods that insert, update, and delete:
TODO: update columns
```swift
try pointOfInterest.insert(db) // INSERT
try pointOfInterest.update(db) // UPDATE
try pointOfInterest.save(db) // Inserts or updates
try pointOfInterest.delete(db) // DELETE
pointOfInterest.exists(db) // Bool
try pointOfInterest.insert(db) // INSERT
try pointOfInterest.update(db) // UPDATE
try pointOfInterest.update(db, columns: ...) // UPDATE
try pointOfInterest.save(db) // Inserts or updates
try pointOfInterest.delete(db) // DELETE
pointOfInterest.exists(db) // Bool
```
- `insert`, `update`, `save` and `delete` can throw a [DatabaseError](#error-handling) whenever an SQLite integrity check fails.
+1
View File
@@ -1,4 +1,5 @@
- [ ] Partial update. update(db) should call update(db, columns: [String]) (single point of override)
- [ ] cache columns
- [ ] Fix "More, when you're interested in specific table columns, you're out of luck, because databaseDidChange does not know about columns: it just knows that a row has been inserted, deleted, or updated, without further detail"
- [ ] GRDBCipher: remove limitations on iOS or OS X versions
- [ ] FetchedRecordsController: take inspiration from https://github.com/jflinter/Dwifft