@@ -2,6 +2,13 @@ import 'package:sqlite3/common.dart';
2
2
3
3
import '../sqlite_connection.dart' ;
4
4
5
+ /// A context that can be used to run both reading and writing queries -
6
+ /// basically a [SqliteWriteContext] without the ability to start transactions.
7
+ ///
8
+ /// Instances of this are not given out to clients - instead, they are wrapped
9
+ /// with [ScopedReadContext] and [ScopedWriteContext] after obtaining a lock.
10
+ /// Those wrapped views have a shorter lifetime (they can be closed
11
+ /// independently, and verify that they're not being used after being closed).
5
12
abstract base class UnscopedContext implements SqliteReadContext {
6
13
Future <ResultSet > execute (String sql, List <Object ?> parameters);
7
14
Future <void > executeBatch (String sql, List <List <Object ?>> parameterSets);
@@ -17,6 +24,7 @@ abstract base class UnscopedContext implements SqliteReadContext {
17
24
}
18
25
}
19
26
27
+ /// A view over an [UnscopedContext] implementing [SqliteReadContext] .
20
28
final class ScopedReadContext implements SqliteReadContext {
21
29
final UnscopedContext _context;
22
30
@@ -91,6 +99,11 @@ final class ScopedReadContext implements SqliteReadContext {
91
99
92
100
void invalidate () => _closed = true ;
93
101
102
+ /// Creates a short-lived wrapper around the [unsafe] context to safely give
103
+ /// [callback] read-access to the database.
104
+ ///
105
+ /// Assumes that a read lock providing sound access to the inner
106
+ /// [UnscopedContext] is held until this future returns.
94
107
static Future <T > assumeReadLock <T >(
95
108
UnscopedContext unsafe,
96
109
Future <T > Function (SqliteReadContext ) callback,
@@ -178,6 +191,11 @@ final class ScopedWriteContext extends ScopedReadContext
178
191
};
179
192
}
180
193
194
+ /// Creates a short-lived wrapper around the [unsafe] context to safely give
195
+ /// [callback] access to the database.
196
+ ///
197
+ /// Assumes that a write lock providing sound access to the inner
198
+ /// [UnscopedContext] is held until this future returns.
181
199
static Future <T > assumeWriteLock <T >(
182
200
UnscopedContext unsafe,
183
201
Future <T > Function (SqliteWriteContext ) callback,
0 commit comments