54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:jadb/_data_ingestion/kanjivg/objects.dart';
|
|
import 'package:jadb/table_names/kanjivg.dart';
|
|
import 'package:sqflite_common/sqflite.dart';
|
|
|
|
Future<void> seedKanjiVGData(Iterable<KanjiVGItem> items, Database db) {
|
|
return db.transaction((txn) async {
|
|
await txn.execute('PRAGMA defer_foreign_keys = ON');
|
|
|
|
final b = txn.batch();
|
|
|
|
for (final item in items) {
|
|
b.insert(KanjiVGTableNames.entry, item.sqlValue);
|
|
|
|
for (final path in item.paths) {
|
|
b.insert(
|
|
KanjiVGTableNames.path,
|
|
path.sqlValue..addAll({'character': item.character}),
|
|
);
|
|
}
|
|
|
|
for (final strokeNumber in item.strokeNumbers) {
|
|
b.insert(
|
|
KanjiVGTableNames.strokeNumber,
|
|
strokeNumber.sqlValue..addAll({'character': item.character}),
|
|
);
|
|
}
|
|
|
|
for (final pathGroup in item.pathGroups) {
|
|
_insertPathGroup(b, null, pathGroup, item.character);
|
|
}
|
|
}
|
|
|
|
await b.commit(noResult: true);
|
|
});
|
|
}
|
|
|
|
/// Recursively insert path groups and their children
|
|
void _insertPathGroup(
|
|
Batch b,
|
|
int? parentGroupId,
|
|
KanjiPathGroupTreeNode node,
|
|
String character,
|
|
) {
|
|
b.insert(
|
|
KanjiVGTableNames.pathGroup,
|
|
node.sqlValue
|
|
..addAll({'character': character, 'parentGroupId': parentGroupId}),
|
|
);
|
|
|
|
for (final child in node.children) {
|
|
_insertPathGroup(b, node.id, child, character);
|
|
}
|
|
}
|