push
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:lensai/extensions/nullable.dart';
|
||||
import 'package:lensai/features/user/data/database/database.dart';
|
||||
|
||||
part 'setting.g.dart';
|
||||
@@ -7,12 +10,16 @@ part 'setting.g.dart';
|
||||
class SettingDao extends DatabaseAccessor<UserDatabase> with _$SettingDaoMixin {
|
||||
SettingDao(super.attachedDatabase);
|
||||
|
||||
Future<int> updateSetting(String key, Object? value) {
|
||||
final driftvalue = (value != null) ? DriftAny(value) : null;
|
||||
Future<int> updateSetting(String key, String? partitionKey, Object? value) {
|
||||
final normalizedValue = (value is Iterable) ? jsonEncode(value) : value;
|
||||
|
||||
final driftvalue = normalizedValue
|
||||
.mapNotNull((normalizedValue) => DriftAny(normalizedValue));
|
||||
|
||||
return db.setting.insertOne(
|
||||
SettingCompanion.insert(
|
||||
key: key,
|
||||
partitionKey: Value(partitionKey),
|
||||
value: Value(driftvalue),
|
||||
),
|
||||
onConflict: DoUpdate(
|
||||
@@ -21,7 +28,12 @@ class SettingDao extends DatabaseAccessor<UserDatabase> with _$SettingDaoMixin {
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<MapEntry<String, DriftAny?>> allSettings() {
|
||||
return db.setting.select().map((row) => MapEntry(row.key, row.value));
|
||||
Selectable<MapEntry<String, DriftAny?>> allSettingsOfPartitionKey(
|
||||
String? partitionKey,
|
||||
) {
|
||||
final query = db.setting.select()
|
||||
..where((r) => r.partitionKey.equalsNullable(partitionKey));
|
||||
|
||||
return query.map((row) => MapEntry(row.key, row.value));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user