mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
DatabaseSnapshot RAII
This commit is contained in:
1 parent
70437bd4cb
commit
dbfbe30749
1 file changed
+8
-1
@@ -29,7 +29,7 @@ public class DatabaseSnapshot : DatabaseReader {
|
||||
throw DatabaseError(message: "WAL mode is not activated at path: \(path)")
|
||||
}
|
||||
|
||||
// Establish snapshot isolation
|
||||
// Establish snapshot isolation (see deinit)
|
||||
try db.beginTransaction(.deferred)
|
||||
|
||||
// Take snapshot
|
||||
@@ -37,6 +37,13 @@ public class DatabaseSnapshot : DatabaseReader {
|
||||
try db.makeSelectStatement("SELECT rootpage FROM sqlite_master").cursor().next()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
// Leave snapshot isolation
|
||||
serializedDatabase.sync { db in
|
||||
try? db.commit()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DatabaseReader
|
||||
|
||||
Reference in new issue
Block a user