Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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> get allConnections;
}
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> get allConnections {
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> get allConnections {
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> get allConnections {
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> get allConnections {
return _pool.allConnections;
}
}
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> get allConnections {
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> get allConnections {
return [_connection];
}
}