Commit 25efc670 authored by nanahira's avatar nanahira

fix

parent aa0c242a
...@@ -115,8 +115,10 @@ export class DBReader extends Base { ...@@ -115,8 +115,10 @@ export class DBReader extends Base {
cndb: Database; cndb: Database;
outputdb: Database; outputdb: Database;
overrideTextDb: Database; overrideTextDb: Database;
async openDatabase(path: string) { async openDatabase(path: string, mustExist: boolean = false) {
await fs.access(path); if (mustExist) {
await fs.access(path);
}
return await open({ return await open({
filename: path, filename: path,
driver: sqlite3.Database driver: sqlite3.Database
...@@ -125,8 +127,8 @@ export class DBReader extends Base { ...@@ -125,8 +127,8 @@ export class DBReader extends Base {
async init() { async init() {
await super.init(); await super.init();
this.log.debug(`Opening databases...`); this.log.debug(`Opening databases...`);
this.cndb = await this.openDatabase(this.config.cnDatabasePath); this.cndb = await this.openDatabase(this.config.cnDatabasePath, true);
this.jpdb = await this.openDatabase(this.config.jpDatabasePath); this.jpdb = await this.openDatabase(this.config.jpDatabasePath, true);
this.overrideTextDb = this.config.overrideTextDbPath ? await this.openDatabase(this.config.overrideTextDbPath) : null; this.overrideTextDb = this.config.overrideTextDbPath ? await this.openDatabase(this.config.overrideTextDbPath) : null;
} }
async finalize() { async finalize() {
...@@ -270,7 +272,7 @@ export class DBReader extends Base { ...@@ -270,7 +272,7 @@ export class DBReader extends Base {
async getAllCardsFromDatabase(dbPath: string) { async getAllCardsFromDatabase(dbPath: string) {
try { try {
const db = await this.openDatabase(dbPath); const db = await this.openDatabase(dbPath, true);
const codes: number[] = (await db.all('SELECT id FROM datas where type & 0x4000 = 0 and not exists (select 1 from datas orig where orig.id = datas.alias and orig.id < datas.id and orig.id >= (datas.id - 20))')).map(m => m.id); const codes: number[] = (await db.all('SELECT id FROM datas where type & 0x4000 = 0 and not exists (select 1 from datas orig where orig.id = datas.alias and orig.id < datas.id and orig.id >= (datas.id - 20))')).map(m => m.id);
await db.close(); await db.close();
return codes; return codes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment