What's right approach to load database (sqlite)?


#1

Hey guys,

I have been working on development mode, now I’m trying to build/package it.

I have a SQLite database located at ./app/services/db/database.db , after build it, where would it be located ?

~/Library/Application Support/MyElectronApp ?

I tried to load it in this way:

const path = require('path')
const dbPath = path.resolve(__dirname, './app/services/db/my_database.db')
I works for development, but not for production. On production, when I load the package, it says ‘unable to load database’.

Another question, should I create the database table at run time, or can I have the database tables ready in my .db file ?


#2

Have you read this documentation?


#3

thanks @DamnedScholar , that helped, the final solution for me was:

const electron = require('electron')
const { app } = electron
const path = require('path')
const Database = require("better-sqlite3");

const userData = app.getPath('userData',)
const dbFile = path.resolve(userData, 'my_database.db')
const db = new Database(dbFile);