Database.checkpoint

This commit is contained in:
Gwendal Roué committed 2019-10-10 13:45:01 +02:00
1 parent fc57a69672
commit b3e1bf6f05
2 files changed
+10 -8

No files matched your search

+9 -1
View File
@@ -629,7 +629,15 @@ extension Database {
}
extension Database {
func checkpoint(_ kind: Database.CheckpointMode) throws {
let code = sqlite3_wal_checkpoint_v2(sqliteConnection, nil, kind.rawValue, nil, nil)
guard code == SQLITE_OK else {
throw DatabaseError(resultCode: code, message: lastErrorMessage)
}
}
}
extension Database {
// MARK: - Transactions & Savepoint
/// Executes a block inside a database transaction.
+1 -7
View File
@@ -154,13 +154,7 @@ extension DatabasePool {
/// - parameter kind: The checkpoint mode (default passive)
public func checkpoint(_ kind: Database.CheckpointMode = .passive) throws {
try writer.sync { db in
// TODO: read https://www.sqlite.org/c3ref/wal_checkpoint_v2.html and
// check whether we need a busy handler on writer and/or readers
// when kind is not .Passive.
let code = sqlite3_wal_checkpoint_v2(db.sqliteConnection, nil, kind.rawValue, nil, nil)
guard code == SQLITE_OK else {
throw DatabaseError(resultCode: code, message: db.lastErrorMessage)
}
try db.checkpoint(kind)
}
}
}