From 5613a12111dfc2a94769d4f8ef4dcf217cb25559 Mon Sep 17 00:00:00 2001 From: styx11 <1654630248@qq.com> Date: Tue, 20 Apr 2021 11:08:33 +0800 Subject: [PATCH] fix: await sqlite db creation (#2) --- bin/whats.js | 26 +++++++++++++++++--------- package.json | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/whats.js b/bin/whats.js index 351bbed..411e3fb 100755 --- a/bin/whats.js +++ b/bin/whats.js @@ -82,14 +82,22 @@ if (rawRecord && typeof rawRecord === 'string') { // For now, it's easily to fail to find the database file by spreading the database creation, // so we'll have to create it in the first place const db = new sqlite.cached.Database(dbPath); -tableCreated(dbPath).then(created => { - const dbOpts = { db, created }; - config.dbOpts = dbOpts; - program.record - ? record() - : whats(program.from, program.to); + +db.on('open', () => { + tableCreated(dbPath).then(created => { + const dbOpts = { db, created }; + config.dbOpts = dbOpts; + program.record + ? record() + : whats(program.from, program.to); + }) + .catch(e => { + console.log(logSymbols.error + ' ' + e.message); + db.close(); + }); }) -.catch(e => { - console.log(logSymbols.error + ' ' + e.message); + +db.on('error', (e) => { + console.log(logSymbols.error + ' ' + e); db.close(); -}); +}) diff --git a/package.json b/package.json index 0df80cc..ab8594b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "what-is-x", - "version": "0.6.10", + "version": "0.6.11", "description": "a terminal translation tool", "main": "index.js", "bin": {