mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Persistable.delete() uses DatabaseWriter instead of Database
This commit is contained in:
1 parent
50cc857a3a
commit
18b996e5bd
4 files changed
+19
-16
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user