Reputation: 1373
I have an Electron JS application that uses a local sqlite database. The sqlite database is a file within the project folder structure (lib folder). The application works just fine during testing, but when I build the app on Mac, and launch the .dmg file, it gets an error saying it cannot find the .sqlite database.
Is there a way to get this to work with the sqlite database I have in my project? Or is there a simpler way to do local storage in an Electron app?
Thank you.
Upvotes: 0
Views: 2200
Reputation: 51
You must add buildResources
extraResources
in package.json
to grab the SQLite file in production.
"build": {
"appId": "com.app.app",
"productName": "Electron APP",
"files": [
"build/**/*"
],
"directories": {
"buildResources": "build"
},
"extraResources": [
{
"from": "./db/",
"to": "db/",
"filter": [
"**/*"
]
}
],
},
Upvotes: 0
Reputation: 1373
I found out this can be accomplished by writing the SQLite file to the local user's directory:
const electron = require('electron');
const path = require('path');
const userDir = (electron.app || electron.remote.app).getPath('userData');
const dbPath = path.join(userDir, 'mydb.sqlite');
Upvotes: 1