tmotagam / sqlite-electron

module for electron to use sqlite3 databases

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot create database file sqlite.setdbPath

minevbg opened this issue · comments

I cannot create a database with sqlite.setdbPath.

Obviously, nothing else works after that.

(async () => {
  try {
    await sqlite.setdbPath('./sqlite_master.db');
    console.log('DB file created!');
}
  catch(err) {
    console.log(err);
  }
})()

Here is the error from console:

(node:19936) UnhandledPromiseRejectionWarning: Error: Cannot set path
    at electronNodeDetection (D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:77:19)
    at D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:99:26
    at step (D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:33:23)
    at Object.next (D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:14:53)
    at D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:4:12)
    at Object.setdbPath (D:\test\myproj\node_modules\sqlite-electron\cjs\sqlite-electron.js:88:12)
    at Object.<anonymous> (D:\test\myproj\out\main\main.js:23:8)
    at Module._compile (node:internal/modules/cjs/loader:1271:14)
(Use `electron --trace-warnings ...` to show where the warning was created)
(node:19936) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
[19936:0219/204913.235:ERROR:cert_issuer_source_aia.cc(34)] Error parsing cert retrieved from AIA (as DER):
ERROR: Couldn't read tbsCertificate as SEQUENCE
ERROR: Failed parsing Certificate

Same error if I try to do it with URI - sqlite.setdbPath("file:tutorial.db?mode:rw", isuri=true)

It only works fine when I try to make it in memory with sqlite.setdbPath(":memory:"), no errors and sqlite executable is running.

Any idea on how to troubleshoot this?

Electron version v28.2.3

Hello @minevbg,
Please use the API like this for create the .db file, it will create the file automatically if it doesn't exists or open the already existing file.

(async () => {
try {
  await sqlite.setdbPath('demo.db');
  console.log('DB file created!');
}
catch(err) {
  console.log(err);
}
})()

In your URI code use it like this and also read this link SQLITE URI.

sqlite.setdbPath("file:tutorial.db?mode:rwc", isuri=true)

regards.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I'm having this same problem. This is from my main.js file:

app.whenReady().then(() => {
  ipcMain.handle("databasePath", async (event, dbPath) => {
    return (async () => {
      try {
        await sqlite.setdbPath(dbPath);
        console.log("DB file created!");
      } catch (err) {
        console.log(err);
      }
    })();
  });
  createWindow();
});

I've checked that the dbPath value is correctly passed in from the render process.

When I inspect require.main, I do see that it is undefined, which is the technical cause of the error (https://github.com/tmotagam/sqlite-electron/blob/master/sqlite-electron.ts#L26). I don't understand why this would be undefined, since this should be running in the main process.

I'm running on Windows 11 with electron v. 29.1.5.

Do you have any suggestions?