Using local database after electron build
See original GitHub issueHey all. I’m currently using Electron 5.0.1, Vue 2.6, and The Electron Builder v1.3.1. I’m having trouble getting SQLite to work when I’m trying to build a MacOS or Windows app.
Here’s what my vue.config.js
looks like:
module.exports = {
css: {
loaderOptions: {
sass: {
data: `
@import "@/styles/main.scss";
`,
},
},
},
configureWebpack: {
externals: {
sequelize: "require('sequelize')",
},
},
pluginOptions: {
electronBuilder: {
externals: ['sequelize'],
builderOptions: {
extraResources: ['src/data.db'],
},
}
},
};
and Here’s how I connect via my db:
import Sequelize from 'sequelize';
import Component from '@/models/component';
import Element from '@/models/element';
import Kiosk from '@/models/kiosk';
import Page from '@/models/page';
import path from 'path';
const isBuild = process.env.NODE_ENV === 'production';
const pathToDbFile = path.join( // eslint-disable-next-line
(isBuild ? __dirname : __static),
(isBuild ? '../../' : ''),
'../src/data.db',
);
// setup the connection to make sure it works
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: pathToDbFile,
logging: (process.env.NODE_ENV !== 'production') ? console.log : false,
define: {
timestamps: false,
underscored: true,
},
});
const db = {};
// test for the connection
if (process.env.NODE_ENV !== 'production') {
sequelize.authenticate()
.then(() => {
console.log('Connection has been established.');
})
.catch(console.error);
}
db.Component = Component.init(sequelize);
db.Element = Element.init(sequelize);
db.Kiosk = Kiosk.init(sequelize);
db.Page = Page.init(sequelize);
Object.keys(db).forEach((modelName) => {
if (db[modelName].associate) db[modelName].associate(db);
});
db.Sequelize = Sequelize;
db.sequelize = sequelize;
export default db;
Any idea what’s going on?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to use a local database (SQLite or NeDB) after build?
I'm trying to use a local database in my electron app, it works in development but when i bundled the app (I only...
Read more >How to embed a database in your electron app | by
In this post, I'll walk through my NEDB setup. It's fairly simple and is being used in production at HTTPSLocalhost app. nedb-promises is...
Read more >Is it possible to have local database file used by Electron ...
Yes, you can easily create and use a local database in an Electron app using an npm package like node-sqlite3.
Read more >Electron local Database : r/electronjs
I am creating an electron application which will be 100% offline all data will be stored on computer system, but data can go...
Read more >Local Data storage for Electron
ajv is a JSON schema validator library. Schema validator is optional to build the NoSQL database, but I'd recommend using it since well-defined ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Use this:
not sure why the path changed, but this works now.
externals: ['sequelize']
in the vue.config.js works for me