How do I access a Sqlite3 database from an Electron AppImage .mount point?

333 Views Asked by At
  • OS: Linux 5.9.16-1-MANJARO
  • Electron version: 10.1.5
  • BetterSqlite version: 7.1.2

I am currently writing an application using Electron and BetterSqlite.

I build the AppImage like this:

npm run build && electron-builder build

This is how I access the database from my code:

db = new Database(
    path.join(__dirname, `/${dbName}`).replace("/app.asar", "")
);

I have added the database file to use using:

"extraResources": [
    "public/build/Database.db"
],

But when I open the AppImage i get the following error message:

SqliteError: attempt to write a readonly database

The database seems to be inaccessible due to the /tmp/.mountxxx point being readonly.

This behavior does not occur when I open the application in the development folder since it's not a readonly directory.

Is there a way to use the database from the /tmp/.mountxxx directory?

How would I got about accessing the database another way?

Thank you in advance.

2

There are 2 best solutions below

0
On

I have searched for a way to use the AppImage mount point to read and write but I have not found anything. I will be using the user's home directory to store the database

0
On

As the error says when an AppImage is executed the AppDir is mounted as RO filesystem.

To workaround this you need to copy the database file into the user home using an startup script. By example you can copy it to "$HOME/.cache/com.myapp/appdata.db" then use this new copy.