Skip to content

Commit 97bc2c8

Browse files
committed
Docs
1 parent d155459 commit 97bc2c8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/sqlite_async/lib/src/impl/context.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import 'package:sqlite3/common.dart';
22

33
import '../sqlite_connection.dart';
44

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).
512
abstract base class UnscopedContext implements SqliteReadContext {
613
Future<ResultSet> execute(String sql, List<Object?> parameters);
714
Future<void> executeBatch(String sql, List<List<Object?>> parameterSets);
@@ -17,6 +24,7 @@ abstract base class UnscopedContext implements SqliteReadContext {
1724
}
1825
}
1926

27+
/// A view over an [UnscopedContext] implementing [SqliteReadContext].
2028
final class ScopedReadContext implements SqliteReadContext {
2129
final UnscopedContext _context;
2230

@@ -91,6 +99,11 @@ final class ScopedReadContext implements SqliteReadContext {
9199

92100
void invalidate() => _closed = true;
93101

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.
94107
static Future<T> assumeReadLock<T>(
95108
UnscopedContext unsafe,
96109
Future<T> Function(SqliteReadContext) callback,
@@ -178,6 +191,11 @@ final class ScopedWriteContext extends ScopedReadContext
178191
};
179192
}
180193

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.
181199
static Future<T> assumeWriteLock<T>(
182200
UnscopedContext unsafe,
183201
Future<T> Function(SqliteWriteContext) callback,

0 commit comments

Comments
 (0)