database.js: add hasSequences

This commit is contained in:
siikamiika 2017-10-24 13:45:51 +03:00
parent 8400f0e4c0
commit df0d2beb73

View File

@ -233,7 +233,7 @@ class Database {
throw 'Database not initialized'; throw 'Database not initialized';
} }
const indexDataLoaded = async summary => { const indexDataValid = async summary => {
if (summary.version > 2) { if (summary.version > 2) {
throw 'Unsupported dictionary version'; throw 'Unsupported dictionary version';
} }
@ -242,7 +242,9 @@ class Database {
if (count > 0) { if (count > 0) {
throw 'Dictionary is already imported'; throw 'Dictionary is already imported';
} }
};
const indexDataLoaded = async summary => {
await this.db.dictionaries.add(summary); await this.db.dictionaries.add(summary);
}; };
@ -280,6 +282,8 @@ class Database {
} }
} }
summary.hasSequences = rows.every(row => row.sequence >= 0);
await this.db.terms.bulkAdd(rows); await this.db.terms.bulkAdd(rows);
}; };
@ -377,6 +381,7 @@ class Database {
return await Database.importDictionaryZip( return await Database.importDictionaryZip(
archive, archive,
indexDataValid,
indexDataLoaded, indexDataLoaded,
termDataLoaded, termDataLoaded,
termMetaDataLoaded, termMetaDataLoaded,
@ -388,6 +393,7 @@ class Database {
static async importDictionaryZip( static async importDictionaryZip(
archive, archive,
indexDataValid,
indexDataLoaded, indexDataLoaded,
termDataLoaded, termDataLoaded,
termMetaDataLoaded, termMetaDataLoaded,
@ -413,9 +419,7 @@ class Database {
version: index.format || index.version version: index.format || index.version
}; };
if (indexDataLoaded) { await indexDataValid(summary);
await indexDataLoaded(summary);
}
const buildTermBankName = index => `term_bank_${index + 1}.json`; const buildTermBankName = index => `term_bank_${index + 1}.json`;
const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`; const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`;
@ -472,6 +476,10 @@ class Database {
await loadBank(summary, buildKanjiMetaBankName, kanjiMetaBankCount, kanjiMetaDataLoaded); await loadBank(summary, buildKanjiMetaBankName, kanjiMetaBankCount, kanjiMetaDataLoaded);
await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded); await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded);
if (indexDataLoaded) {
await indexDataLoaded(summary);
}
return summary; return summary;
} }
} }