Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/sqlite_async/lib/src/common/sqlite_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ abstract class SqliteDatabase
factory SqliteDatabase.singleConnection(SqliteConnection connection) {
return SingleConnectionDatabase(connection);
}

/// Returns a list of all the connections (read and write) managed by this database.
/// This can be useful to run the same statement on all connections. For instance,
/// ATTACHing a database, that is expected to be available in all connections.
List<SqliteConnection> getAllConnections();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ final class SingleConnectionDatabase
return connection.writeLock(callback,
lockTimeout: lockTimeout, debugContext: debugContext);
}

@override
List<SqliteConnection> getAllConnections() {
return [connection];
}
}
5 changes: 5 additions & 0 deletions packages/sqlite_async/lib/src/impl/stub_sqlite_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ class SqliteDatabaseImpl
Future<bool> getAutoCommit() {
throw UnimplementedError();
}

@override
List<SqliteConnection> getAllConnections() {
throw UnimplementedError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ class SqliteConnectionPool with SqliteQueries implements SqliteConnection {
await connection.refreshSchema();
}
}

List<SqliteConnection> getAllConnections() {
final connections = <SqliteConnection>[];
if (_writeConnection != null) {
connections.add(_writeConnection!);
}
connections.addAll(_allReadConnections);
return connections;
}
}

typedef ReadCallback<T> = Future<T> Function(SqliteReadContext tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,9 @@ class SqliteDatabaseImpl
Future<void> refreshSchema() {
return _pool.refreshSchema();
}

@override
List<SqliteConnection> getAllConnections() {
return _pool.getAllConnections();
}
}
5 changes: 5 additions & 0 deletions packages/sqlite_async/lib/src/web/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ class WebDatabase
await isInitialized;
return _database.fileSystem.flush();
}

@override
List<SqliteConnection> getAllConnections() {
return [this];
}
}

final class _UnscopedContext extends UnscopedContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,9 @@ class SqliteDatabaseImpl
Future<WebDatabaseEndpoint> exposeEndpoint() async {
return await _connection.exposeEndpoint();
}

@override
List<SqliteConnection> getAllConnections() {
return [_connection];
}
}