42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
import 'package:jadb/table_names/jmdict.dart';
|
|
import 'package:jadb/table_names/kanjidic.dart';
|
|
import 'package:jadb/table_names/radkfile.dart';
|
|
import 'package:jadb/table_names/tanos_jlpt.dart';
|
|
import 'package:sqflite_common/sqlite_api.dart';
|
|
|
|
Future<void> verifyTablesWithDbConnection(DatabaseExecutor db) async {
|
|
final Set<String> tables = await db
|
|
.query(
|
|
'sqlite_master',
|
|
columns: ['name'],
|
|
where: 'type = ?',
|
|
whereArgs: ['table'],
|
|
)
|
|
.then((result) {
|
|
return result.map((row) => row['name'] as String).toSet();
|
|
});
|
|
|
|
final Set<String> expectedTables = {
|
|
...JMdictTableNames.allTables,
|
|
...KANJIDICTableNames.allTables,
|
|
...RADKFILETableNames.allTables,
|
|
...TanosJLPTTableNames.allTables,
|
|
};
|
|
|
|
final missingTables = expectedTables.difference(tables);
|
|
|
|
if (missingTables.isNotEmpty) {
|
|
throw Exception(
|
|
[
|
|
'Missing tables:',
|
|
missingTables.map((table) => ' - $table').join('\n'),
|
|
'',
|
|
'Found tables:\n',
|
|
tables.map((table) => ' - $table').join('\n'),
|
|
'',
|
|
'Please ensure the database is correctly set up.',
|
|
].join('\n'),
|
|
);
|
|
}
|
|
}
|