Initial project
This commit is contained in:
24
apps/im_app/lib/app/di/db_provider.dart
Normal file
24
apps/im_app/lib/app/di/db_provider.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:storage_sdk/storage_sdk.dart';
|
||||
|
||||
import '../../data/local/drift/app_database.dart';
|
||||
|
||||
/// 全局单例 StorageSdkApi,整个 App 生命周期内唯一实例。
|
||||
///
|
||||
/// storage_sdk 负责数据库连接生命周期和 CRUD 机制;
|
||||
/// im_app 负责 schema(AppDatabase + 各业务表)。
|
||||
///
|
||||
/// 用法:
|
||||
/// ```dart
|
||||
/// // 登录后开库
|
||||
/// await ref.read(storageSdkProvider).openDatabase(user.id);
|
||||
///
|
||||
/// // CRUD 示例
|
||||
/// final db = ref.read(storageSdkProvider);
|
||||
/// await db.insertOrReplace(appDb.users, companion);
|
||||
/// ```
|
||||
final storageSdkProvider = Provider<StorageSdkApi>((ref) {
|
||||
return StorageSdkApi(
|
||||
databaseFactory: (executor) => AppDatabase(executor),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user