Persistable.delete() uses DatabaseWriter instead of Database

This commit is contained in:
Gwendal Roué committed 2016-03-11 18:56:09 +01:00
1 parent 50cc857a3a
commit 18b996e5bd
4 files changed
+19 -16

No files matched your search

+7 -5
View File
@@ -146,7 +146,7 @@ public protocol MutablePersistable : TableMapping {
///
/// - returns: Whether a database row was deleted.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
func delete(db: Database) throws -> Bool
func delete(writer: DatabaseWriter) throws -> Bool
/// Returns true if and only if the primary key matches a row in
/// the database.
@@ -194,8 +194,8 @@ public extension MutablePersistable {
/// Executes a DELETE statement.
///
/// The default implementation for delete() invokes performDelete().
func delete(db: Database) throws -> Bool {
return try performDelete(db)
func delete(writer: DatabaseWriter) throws -> Bool {
return try performDelete(writer)
}
/// Returns true if and only if the primary key matches a row in
@@ -292,8 +292,10 @@ public extension MutablePersistable {
/// that adopt MutablePersistable can invoke performDelete() in
/// their implementation of delete(). They should not provide their own
/// implementation of performDelete().
func performDelete(db: Database) throws -> Bool {
return try DataMapper(db, self).deleteStatement().execute().changedRowCount > 0
func performDelete(writer: DatabaseWriter) throws -> Bool {
return try writer._write { db in
try DataMapper(db, self).deleteStatement().execute().changedRowCount > 0
}
}
/// Don't invoke this method directly: it is an internal method for types
+8 -7
View File
@@ -285,13 +285,14 @@ public class Record : RowConvertible, TableMapping, Persistable {
///
/// - returns: Whether a database row was deleted.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public func delete(db: Database) throws -> Bool {
let deleted = try performDelete(db)
// Future calls to update() will throw NotFound. Make the user
// a favor and make sure this error is thrown even if she checks the
// hasPersistentChangedValues flag:
hasPersistentChangedValues = true
return deleted
public func delete(writer: DatabaseWriter) throws -> Bool {
defer {
// Future calls to update() will throw NotFound. Make the user
// a favor and make sure this error is thrown even if she checks the
// hasPersistentChangedValues flag:
hasPersistentChangedValues = true
}
return try performDelete(writer)
}
}
@@ -73,9 +73,9 @@ struct MutablePersistableCustomizedCountry : MutablePersistable {
try performSave(writer)
}
func delete(db: Database) throws {
func delete(writer: DatabaseWriter) throws {
willDelete()
try performDelete(db)
try performDelete(writer)
}
func exists(db: Database) -> Bool {
@@ -83,9 +83,9 @@ struct PersistableCustomizedCountry : Persistable {
try performSave(writer)
}
func delete(db: Database) throws {
func delete(writer: DatabaseWriter) throws {
willDelete()
try performDelete(db)
try performDelete(writer)
}
func exists(db: Database) -> Bool {