Skip to content

Commit aefc3c7

Browse files
committed
settings: Make general int global settings
1 parent 2a163b2 commit aefc3c7

File tree

10 files changed

+1768
-9
lines changed

10 files changed

+1768
-9
lines changed

lib/model/database.dart

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ class BoolGlobalSettings extends Table {
7373
Set<Column<Object>>? get primaryKey => {name};
7474
}
7575

76+
@DataClassName('IntGlobalSettingRow')
77+
class IntGlobalSettings extends Table {
78+
TextColumn get name => text()();
79+
80+
IntColumn get value => integer()();
81+
82+
@override
83+
Set<Column<Object>>? get primaryKey => {name};
84+
}
85+
7686
/// The table of [Account] records in the app's database.
7787
class Accounts extends Table {
7888
/// The ID of this account in the app's local database.
@@ -116,7 +126,7 @@ class UriConverter extends TypeConverter<Uri, String> {
116126
@override Uri fromSql(String fromDb) => Uri.parse(fromDb);
117127
}
118128

119-
@DriftDatabase(tables: [GlobalSettings, BoolGlobalSettings, Accounts])
129+
@DriftDatabase(tables: [GlobalSettings, BoolGlobalSettings, IntGlobalSettings, Accounts])
120130
class AppDatabase extends _$AppDatabase {
121131
AppDatabase(super.e);
122132

@@ -129,7 +139,7 @@ class AppDatabase extends _$AppDatabase {
129139
// information on using the build_runner.
130140
// * Write a migration in `_migrationSteps` below.
131141
// * Write tests.
132-
static const int latestSchemaVersion = 9; // See note.
142+
static const int latestSchemaVersion = 10; // See note.
133143

134144
@override
135145
int get schemaVersion => latestSchemaVersion;
@@ -200,7 +210,10 @@ class AppDatabase extends _$AppDatabase {
200210
// assume there wasn't also the legacy app before that.
201211
await m.database.update(schema.globalSettings).write(
202212
RawValuesInsertable({'legacy_upgrade_state': Constant('noLegacy')}));
203-
}
213+
},
214+
from9To10: (m, schema) async {
215+
await m.createTable(schema.intGlobalSettings);
216+
},
204217
);
205218

206219
Future<void> _createLatestSchema(Migrator m) async {
@@ -256,6 +269,14 @@ class AppDatabase extends _$AppDatabase {
256269
return result;
257270
}
258271

272+
Future<Map<IntGlobalSetting, int>> getIntGlobalSettings() async {
273+
return {
274+
for (final row in await select(intGlobalSettings).get())
275+
if (IntGlobalSetting.byName(row.name) case final setting?)
276+
setting: row.value
277+
};
278+
}
279+
259280
Future<int> createAccount(AccountsCompanion values) async {
260281
try {
261282
return await into(accounts).insert(values);

0 commit comments

Comments
 (0)