I'm trying to open an sqlite database file using node-sqlite3 in my Angular + Electron app.
Despite I made sure that the file exists and Electron can read it, when I try to create the sqlite database using:
import * as sqlite from 'sqlite3';
// ...
const path = `${__dirname}/assets/sqlite.db`;
const fs = require('electron').remote.require('fs');
console.log(path);
if (fs.existsSync(AppConfig.sqlitePath)) {
console.log('the file exists');
} else {
console.log('the file does not not');
}
const myDb = new sqlite.Database(path, sqlite.OPEN_READONLY, (error) => {
console.log(error);
});
The file exists, since I got the right console.log
message and it looks like:
/tmp/.mount_xxxxxx/resources/app.asar.unpacked/dist/assets/sqlite.db
However, from new sqlite.Database(...)
I get the following error, as the file didn't exist:
Error: SQLITE_CANTOPEN: unable to open database file