DatabaseSnapshot RAII

This commit is contained in:
Gwendal Roué committed 2018-02-24 17:15:53 +01:00
1 parent 70437bd4cb
commit dbfbe30749
1 file changed
+8 -1
+8 -1
View File
@@ -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