Skip to content

Commit

Permalink
fix: await sqlite db creation (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Styx11 committed Apr 20, 2021
1 parent ebcae21 commit 5613a12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions bin/whats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 5613a12

Please sign in to comment.