1)修改数据库命名,不和业务使用重合。

2)修改user 表,uid为unique, 聊天室文件夹name unique移除
This commit is contained in:
Happi (哈比)
2026-03-07 17:29:32 +08:00
parent 36a4cdab03
commit a066e9d2dc
30 changed files with 531 additions and 208 deletions

View File

@@ -18,19 +18,19 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<void> insertOrReplace<T extends Table, D>(
TableInfo<T, D> table,
Insertable<D> companion,
) async {
TableInfo<T, D> table,
Insertable<D> companion,
) async {
final db = _db;
if (db == null) return;
await db.into(table).insertOnConflictUpdate(companion);
await db.into(table).insert(companion, mode: InsertMode.insertOrReplace);
}
@override
Future<void> insert<T extends Table, D>(
TableInfo<T, D> table,
Insertable<D> companion,
) async {
TableInfo<T, D> table,
Insertable<D> companion,
) async {
final db = _db;
if (db == null) return;
await db.into(table).insert(companion, mode: InsertMode.insertOrIgnore);
@@ -38,13 +38,17 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<void> batchInsertOrReplace<T extends Table, D>(
TableInfo<T, D> table,
List<Insertable<D>> companions,
) async {
TableInfo<T, D> table,
List<Insertable<D>> companions,
) async {
final db = _db;
if (db == null) return;
await db.batch(
(batch) => batch.insertAllOnConflictUpdate(table, companions),
(batch) => batch.insertAll(
table,
companions,
mode: InsertMode.insertOrReplace,
),
);
}
@@ -52,10 +56,10 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<void> updateWhere<T extends Table, D>(
TableInfo<T, D> table,
Insertable<D> companion,
Expression<bool> Function(T) filter,
) async {
TableInfo<T, D> table,
Insertable<D> companion,
Expression<bool> Function(T) filter,
) async {
final db = _db;
if (db == null) return;
await (db.update(table)..where(filter)).write(companion);
@@ -65,9 +69,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<void> deleteWhere<T extends Table, D>(
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
final db = _db;
if (db == null) return;
await (db.delete(table)..where(filter)).go();
@@ -91,9 +95,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<List<D>> selectWhere<T extends Table, D>(
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
final db = _db;
if (db == null) return [];
return (db.select(table)..where(filter)).get();
@@ -101,9 +105,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<D?> selectFirst<T extends Table, D>(
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) async {
final db = _db;
if (db == null) return null;
return (db.select(table)..where(filter)..limit(1)).getSingleOrNull();
@@ -120,9 +124,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Stream<List<D>> watchWhere<T extends Table, D>(
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) {
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) {
final db = _db;
if (db == null) return const Stream.empty();
return (db.select(table)..where(filter)).watch();
@@ -130,9 +134,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Stream<D?> watchFirst<T extends Table, D>(
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) {
TableInfo<T, D> table,
Expression<bool> Function(T) filter,
) {
final db = _db;
if (db == null) return const Stream.empty();
return (db.select(table)..where(filter)..limit(1)).watchSingleOrNull();
@@ -142,24 +146,24 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<List<QueryRow>> rawQuery(
String sql, [
List<Object?> args = const [],
]) async {
String sql, [
List<Object?> args = const [],
]) async {
final db = _db;
if (db == null) return [];
return db
.customSelect(
sql,
variables: args.map((e) => Variable(e)).toList(),
)
sql,
variables: args.map((e) => Variable(e)).toList(),
)
.get();
}
@override
Future<void> rawExecute(
String sql, [
List<Object?> args = const [],
]) async {
String sql, [
List<Object?> args = const [],
]) async {
final db = _db;
if (db == null) return;
await db.customStatement(sql, args);
@@ -169,9 +173,9 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
@override
Future<int> count<T extends Table, D>(
TableInfo<T, D> table, {
Expression<bool> Function(T)? filter,
}) async {
TableInfo<T, D> table, {
Expression<bool> Function(T)? filter,
}) async {
final db = _db;
if (db == null) return 0;
final countExpr = table.$columns.first.count();
@@ -180,4 +184,4 @@ class DatabaseRepositoryImpl implements DatabaseRepository {
final row = await query.getSingle();
return row.read(countExpr) ?? 0;
}
}
}