[Persistence] Add more docs

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-02-01 13:55:29 +05:30
parent 74707093b6
commit b8e9d8efdc
5 changed files with 37 additions and 12 deletions
@@ -1,5 +1,3 @@
//ignore_for_file: public_member_api_docs
import 'dart:io'; import 'dart:io';
import 'dart:isolate'; import 'dart:isolate';
import 'package:moor/ffi.dart'; import 'package:moor/ffi.dart';
@@ -7,10 +5,18 @@ import 'package:moor/isolate.dart';
import 'package:moor/moor.dart'; import 'package:moor/moor.dart';
import 'package:path/path.dart'; import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:stream_chat_persistence/src/stream_chat_persistence_client.dart';
import 'package:stream_chat_persistence/stream_chat_persistence.dart';
import '../moor_chat_database.dart'; import '../moor_chat_database.dart';
/// A Helper class to construct new instances of [MoorChatDatabase] specifically
/// for native platform applications
class SharedDB { class SharedDB {
/// Returns a new instance of [VmDatabase] created using [userId]
/// on a regular isolate.
///
/// Generally used with [ConnectionMode.regular].
static Future<VmDatabase> constructDatabase( static Future<VmDatabase> constructDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
@@ -62,7 +68,11 @@ class SharedDB {
return (await receivePort.first as MoorIsolate); return (await receivePort.first as MoorIsolate);
} }
static Future<MoorChatDatabase> constructOfflineStorage( /// Returns a new instance of [MoorChatDatabase] using the factory constructor
/// [MoorChatDatabase.connect] created on a background isolate.
///
/// Generally used with [ConnectionMode.background].
static Future<MoorChatDatabase> constructMoorChatDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
}) async { }) async {
@@ -1,15 +1,21 @@
//ignore_for_file: public_member_api_docs import 'package:stream_chat_persistence/stream_chat_persistence.dart';
//ignore_for_file: always_declare_return_types
/// A Helper class to construct new instances of [MoorChatDatabase]
class SharedDB { class SharedDB {
static constructDatabase( /// Returns a new instance of database.
///
/// Generally used with [ConnectionMode.regular].
static dynamic constructDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
}) { }) {
throw 'Unsupported Platform'; throw 'Unsupported Platform';
} }
static constructOfflineStorage( /// Return a new instance of moor chat database.
///
/// Generally used with [ConnectionMode.background].
static dynamic constructMoorChatDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
}) { }) {
@@ -1,11 +1,15 @@
//ignore_for_file: public_member_api_docs
//ignore_for_file: always_declare_return_types
import 'package:moor/moor_web.dart'; import 'package:moor/moor_web.dart';
import 'package:stream_chat_persistence/src/stream_chat_persistence_client.dart';
import '../moor_chat_database.dart'; import '../moor_chat_database.dart';
/// A Helper class to construct new instances of [MoorChatDatabase] specifically
/// for Web applications
class SharedDB { class SharedDB {
static constructDatabase( /// Returns a new instance of [WebDatabase] created using [userId].
///
/// Generally used with [ConnectionMode.regular].
static Future<WebDatabase> constructDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
}) async { }) async {
@@ -13,7 +17,11 @@ class SharedDB {
return WebDatabase(dbName, logStatements: logStatements); return WebDatabase(dbName, logStatements: logStatements);
} }
static Future<MoorChatDatabase> constructOfflineStorage( /// Returns a new instance of [MoorChatDatabase] creating using the
/// default constructor.
///
/// Generally used with [ConnectionMode.background].
static Future<MoorChatDatabase> constructMoorChatDatabase(
String userId, { String userId, {
bool logStatements = false, bool logStatements = false,
}) async { }) async {
@@ -43,7 +43,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
return; return;
case ConnectionMode.background: case ConnectionMode.background:
_logger.info('Connecting on background isolate'); _logger.info('Connecting on background isolate');
_db = await SharedDB.constructOfflineStorage(userId); _db = await SharedDB.constructMoorChatDatabase(userId);
return; return;
} }
} }
@@ -20,3 +20,4 @@ dev_dependencies:
test: ^1.15.7 test: ^1.15.7
build_runner: ^1.11.0 build_runner: ^1.11.0
moor_generator: ^3.4.1 moor_generator: ^3.4.1
pedantic: ^1.9.2