@@ -54,67 +54,6 @@ class SqliteConnectionPool with SqliteQueries implements SqliteConnection {
54
54
_writeConnection? .updates? .forEach (updatesController.add);
55
55
}
56
56
57
- /// Executes a provided callback function exclusively across all read and
58
- /// write connections in the pool.
59
- ///
60
- /// This function first locks all read and write connections, collecting their
61
- /// contexts. It then executes the provided [callback] function on each of these
62
- /// contexts. After the [callback] completes for each context, the locks are released.
63
- ///
64
- /// Example usage:
65
- /// ```dart
66
- /// await runExclusive((ctx) async {
67
- /// // Perform some database operation with the ctx
68
- /// await ctx.execute('PRAGMA schema_version');
69
- /// });
70
- /// ```
71
- exclusiveLock <T >(
72
- Future <T > Function (SqliteReadContext tx) callback,
73
- ) async {
74
- final List <Completer <SqliteReadContext >> completers = [];
75
- final List <Completer <void >> releasers = [];
76
-
77
- for (final read in _allReadConnections) {
78
- final completer = Completer <SqliteReadContext >();
79
-
80
- completers.add (completer);
81
- read.readLock ((ctx) async {
82
- completer.complete (ctx);
83
-
84
- final releaser = Completer ();
85
- releasers.add (releaser);
86
-
87
- // Keep this active, close the context when finished
88
- await releaser.future;
89
- });
90
- }
91
-
92
- final writeCompleter = Completer <SqliteReadContext >();
93
- completers.add (writeCompleter);
94
- _writeConnection? .writeLock ((ctx) async {
95
- writeCompleter.complete (ctx);
96
-
97
- final releaser = Completer ();
98
- releasers.add (releaser);
99
- await releaser.future;
100
- });
101
-
102
- // Get all the connection contexts and execute the callback on each of them
103
- final List <SqliteReadContext > contexts = [];
104
- for (final completer in completers) {
105
- contexts.add (await completer.future);
106
- }
107
-
108
- for (final c in contexts) {
109
- await callback (c);
110
- }
111
-
112
- // Release all the releasers
113
- for (final r in releasers) {
114
- r.complete ();
115
- }
116
- }
117
-
118
57
/// Returns true if the _write_ connection is currently in autocommit mode.
119
58
@override
120
59
Future <bool > getAutoCommit () async {
@@ -282,6 +221,17 @@ class SqliteConnectionPool with SqliteQueries implements SqliteConnection {
282
221
// read-only connections first.
283
222
await _writeConnection? .close ();
284
223
}
224
+
225
+ @override
226
+ Future <void > refreshSchema () async {
227
+ final toRefresh = _allReadConnections.toList ();
228
+
229
+ await _writeConnection? .refreshSchema ();
230
+
231
+ for (var connection in toRefresh) {
232
+ await connection.refreshSchema ();
233
+ }
234
+ }
285
235
}
286
236
287
237
typedef ReadCallback <T > = Future <T > Function (SqliteReadContext tx);
0 commit comments