Reputation: 1291
I have a electron app, and I use it together with the create-electron-app
.
My electron main process file resides in the public folder, and so does my sqlite3 database.
When I reference the database in development it works as expected because I can access the path:
F:\www\project-name\public\api\db\demodb01
But in production the path does not exist (hidden behind app.asar I'd say):
C:\Users\userName\AppData\Local\Programs\project-name\resources\app.asar\build\api\db\demodb01
How can I target the database file in production?
Upvotes: 2
Views: 4375
Reputation: 81
I’m using Sequelize with SQLite in an Electron app and I’m saving my database file in the userData directory. Here’s the code I’m using:
const { Sequelize } = require("sequelize");
const path = require("path");
const { app } = require("electron");
const sequelize = new Sequelize({
dialect: "sqlite",
storage: path.join(app.getPath("userData"), "database.sqlite"),
});
module.exports = {
sequelize,
};
In the code above, I’m specifying the database storage path using path.join(app.getPath("userData"), "database.sqlite"). After building my app, I can find the database file at the following location on Windows:
C:\Users\<YourUserName>\AppData\Roaming\<YourAppName>\database.sqlite
Upvotes: 1
Reputation: 1
You have one another solution. Please follow the below steps:
First Install electron-is-dev
Add these codes inside your main.js file: main.js
Now in package.json make the following marked changes: package.json
Thank you.
Upvotes: -1
Reputation: 2829
When storing files in your application you should use app.getPath('userData') to store them outside of your applications scope, which keeps them persisted.
nedb is a common choice for Electron applications since it's a lightweight database written in JavaScript. If you haven't checked it out, I recommend you to do.
Upvotes: 4