fix(persistence): bring back experimental indexedDB on web (#1348)
* fix(persistence): bring back experimental indexedDB on web * chore(persistence): update changelog to be upcoming Co-authored-by: Salvatore Giordano <[email protected]>
This commit is contained in:
co-authored by
Salvatore Giordano
parent
37e01b118b
commit
144d517dea
@@ -15,11 +15,12 @@ import 'package:stream_chat_persistence/stream_chat_persistence.dart';
|
||||
/// specifically for native platform applications.
|
||||
class SharedDB {
|
||||
/// Returns a new instance of [DriftChatDatabase].
|
||||
static DriftChatDatabase constructDatabase(
|
||||
static Future<DriftChatDatabase> constructDatabase(
|
||||
String userId, {
|
||||
bool logStatements = false,
|
||||
ConnectionMode connectionMode = ConnectionMode.regular,
|
||||
}) {
|
||||
bool webUseIndexedDbIfSupported = false, // Ignored on native
|
||||
}) async {
|
||||
final dbName = 'db_$userId';
|
||||
if (connectionMode == ConnectionMode.background) {
|
||||
return DriftChatDatabase.connect(
|
||||
|
||||
@@ -5,10 +5,11 @@ import 'package:stream_chat_persistence/stream_chat_persistence.dart';
|
||||
/// A Helper class to construct new instances of [DriftChatDatabase]
|
||||
class SharedDB {
|
||||
/// Returns a new instance of [DriftChatDatabase].
|
||||
static DriftChatDatabase constructDatabase(
|
||||
static Future<DriftChatDatabase> constructDatabase(
|
||||
String userId, {
|
||||
bool logStatements = false,
|
||||
ConnectionMode connectionMode = ConnectionMode.regular,
|
||||
bool webUseIndexedDbIfSupported = false,
|
||||
}) {
|
||||
throw UnsupportedError(
|
||||
'No implementation of the constructDatabase api provided',
|
||||
|
||||
@@ -7,13 +7,32 @@ import 'package:stream_chat_persistence/src/stream_chat_persistence_client.dart'
|
||||
/// specifically for Web applications.
|
||||
class SharedDB {
|
||||
/// Returns a new instance of [DriftChatDatabase].
|
||||
static DriftChatDatabase constructDatabase(
|
||||
static Future<DriftChatDatabase> constructDatabase(
|
||||
String userId, {
|
||||
bool logStatements = false,
|
||||
ConnectionMode connectionMode = ConnectionMode.regular, // Ignored on web
|
||||
}) {
|
||||
bool webUseIndexedDbIfSupported = false,
|
||||
}) async {
|
||||
final dbName = 'db_$userId';
|
||||
final queryExecutor = WebDatabase(dbName, logStatements: logStatements);
|
||||
final queryExecutor = await _getQueryExecutor(
|
||||
dbName,
|
||||
useIndexedDbIfSupported: webUseIndexedDbIfSupported,
|
||||
logStatements: logStatements,
|
||||
);
|
||||
return DriftChatDatabase(userId, queryExecutor);
|
||||
}
|
||||
|
||||
static Future<WebDatabase> _getQueryExecutor(
|
||||
String dbName, {
|
||||
required bool useIndexedDbIfSupported,
|
||||
required bool logStatements,
|
||||
}) async {
|
||||
if (useIndexedDbIfSupported) {
|
||||
return WebDatabase.withStorage(
|
||||
await DriftWebStorage.indexedDbIfSupported(dbName),
|
||||
logStatements: logStatements,
|
||||
);
|
||||
}
|
||||
return WebDatabase(dbName, logStatements: logStatements);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user