Skip to content

Commit bae227e

Browse files
committed
Motivate update hooks with comment
1 parent 0e4893d commit bae227e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Sources/PowerSyncGRDB/Connections/GRDBConnectionPool.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,16 @@ actor GRDBConnectionPool: SQLiteConnectionPoolProtocol {
5050
func write<T: Sendable>(
5151
onConnection: @Sendable @escaping (SQLiteConnectionLease) throws -> T
5252
) async throws -> T {
53-
// Don't start an explicit transaction, we do this internally
53+
// Don't start an explicit transaction, we do this internally.
5454
let (result, updates) = try await pool.writeWithoutTransaction { database in
55+
// This installs a temporary update hook, which breaks if GRDB had its own. Currently, we rely on
56+
// GRDB only installing update hooks for statements that need it (see https://github.com/groue/GRDB.swift/blob/36e30a6f1ef10e4194f6af0cff90888526f0c115/GRDB/Core/TransactionObserver.swift#L266-L275),
57+
// note that `statementObservations` is set in `statementWillExecute` and cleared after a statement
58+
// has completed or failed.
59+
// So since we have exclusive access to the write connection here, no GRDB-active statement can run and we
60+
// can safely install our own hooks.
61+
// In the future, we would like to use high-level GRDB APIs for this instead. However, we're blocked
62+
// by https://github.com/groue/GRDB.swift/issues/1863 on that.
5563
try collectWrites(db: database.sqliteConnection!) {
5664
try onConnection(GRDBConnectionLease(database: database))
5765
}

0 commit comments

Comments
 (0)