I want to insert a new value and overwrite my SQLite database using this ipc function (electron). Whenever I try to add just one entry to the table, it saves it, but as soon as I close the application the entry is gone. The code I wrote only seems to insert and persist the new entry if I add two entries (only persisting the first one). Any ideas on what might be the issue?
ipcMain.handle("add/Winery", async (event, args) => {
const db = new sqlite3.Database('./database/Test.db', sqlite3.OPEN_READWRITE, (err) => {
if (err) return console.error(err.message);
console.log('Connection successfull in AddWinery');
});
console.log('location : ' + args[0])
console.log('email : ' + args[1])
console.log('phone number : ' + args[2])
console.log('name : ' + args[3])
const sql = 'INSERT INTO WINERY (location, email, phone_number, name) VALUES (?,?,?,?)'
db.run(sql, args, function(err) {
if (err) {
console.log(err.message)
}
console.log("entry added to table")
});
db.close();
const pathToFile = path.join('./', "database", "Test.db")
console.log("The path from which the db is taken in addWineries is : " + pathToFile)
const pathToNewDestination = path.join('C:\\Users\\mario', "Test.db")
console.log("The path that is overwritten after add is: " + pathToNewDestination)
console.log("writing new db file to C:\Users\Mario")
fs.copyFileSync(pathToFile, pathToNewDestination)
console.log("succesfully written file!")
})