Implement basic settings

This commit is contained in:
2025-04-22 00:29:31 +02:00
parent 963f7271a2
commit 900bcd866c
2 changed files with 145 additions and 18 deletions

View File

@@ -28,6 +28,11 @@ CREATE TABLE IF NOT EXISTS scratches (
);
CREATE INDEX IF NOT EXISTS idx_scratches_date ON scratches (date);
CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY NOT NULL,
value TEXT NOT NULL
);
''';
static Future<String> _getDatabasePath() async {
@@ -83,4 +88,27 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_scratches_date_unique ON scratches (date);
rethrow;
}
}
// Settings Management
static Future<String?> getSetting(String key) async {
final List<Map<String, dynamic>> maps = await db.query(
'settings',
columns: ['value'],
where: 'key = ?',
whereArgs: [key],
);
if (maps.isNotEmpty) {
return maps.first['value'] as String?;
}
return null;
}
static Future<void> setSetting(String key, String value) async {
await db.insert(
'settings',
{'key': key, 'value': value},
conflictAlgorithm: ConflictAlgorithm.replace,
);
debugPrint("Setting updated: $key = $value");
}
}