@@ -12,13 +12,13 @@ import SQLite3
1212/// - Provides async streams of table updates for replication.
1313/// - Bridges GRDB's managed connections to PowerSync's lease abstraction.
1414/// - Allows both read and write access to raw SQLite connections.
15- final class GRDBConnectionPool : SQLiteConnectionPoolProtocol {
15+ actor GRDBConnectionPool : SQLiteConnectionPoolProtocol {
1616 let pool : DatabasePool
1717
18- public private ( set ) var tableUpdates : AsyncStream < Set < String > >
18+ let tableUpdates : AsyncStream < Set < String > >
1919 private var tableUpdatesContinuation : AsyncStream < Set < String > > . Continuation ?
2020
21- public init (
21+ init (
2222 pool: DatabasePool
2323 ) {
2424 self . pool = pool
@@ -37,7 +37,7 @@ final class GRDBConnectionPool: SQLiteConnectionPoolProtocol {
3737 tableUpdatesContinuation = tempContinuation
3838 }
3939
40- public func processPowerSyncUpdates( _ updates: Set < String > ) async throws {
40+ func processPowerSyncUpdates( _ updates: Set < String > ) async throws {
4141 try await pool. write { database in
4242 for table in updates {
4343 try database. notifyChanges ( in: Table ( table) )
@@ -47,7 +47,7 @@ final class GRDBConnectionPool: SQLiteConnectionPoolProtocol {
4747 tableUpdatesContinuation? . yield ( updates)
4848 }
4949
50- public func read(
50+ func read(
5151 onConnection: @Sendable @escaping ( SQLiteConnectionLease) throws -> Void
5252 ) async throws {
5353 try await pool. read { database in
@@ -57,28 +57,27 @@ final class GRDBConnectionPool: SQLiteConnectionPoolProtocol {
5757 }
5858 }
5959
60- public func write(
60+ func write(
6161 onConnection: @Sendable @escaping ( SQLiteConnectionLease) throws -> Void
6262 ) async throws {
6363 // Don't start an explicit transaction, we do this internally
64- try await pool. writeWithoutTransaction { database in
64+ let result = try await pool. writeWithoutTransaction { database in
6565 guard let pointer = database. sqliteConnection else {
6666 throw PowerSyncGRDBError . connectionUnavailable
6767 }
6868
69- try withSession (
69+ return try withSession (
7070 db: pointer,
7171 ) {
7272 try onConnection (
7373 GRDBConnectionLease ( database: database)
7474 )
75- } onComplete: { _, changes in
76- self . tableUpdatesContinuation? . yield ( changes)
7775 }
7876 }
77+ tableUpdatesContinuation? . yield ( result. affectedTables)
7978 }
8079
81- public func withAllConnections(
80+ func withAllConnections(
8281 onConnection: @Sendable @escaping ( SQLiteConnectionLease, [ SQLiteConnectionLease] ) throws -> Void
8382 ) async throws {
8483 // FIXME, we currently don't support updating the schema
@@ -89,7 +88,7 @@ final class GRDBConnectionPool: SQLiteConnectionPoolProtocol {
8988 pool. invalidateReadOnlyConnections ( )
9089 }
9190
92- public func close( ) throws {
91+ func close( ) async throws {
9392 try pool. close ( )
9493 }
9594}
0 commit comments