Search code examples
javascriptnode.jselectronknex.jsnode-sqlite3

sqlite3 update query refreshes electron renderer process


I realized that when i use update query with knex (with sqlite3) in electron js, after query done, the renderer process refreshes automatically! for example:

index.html:

ipc.send('UpdateTheRow', {'Id': 1, 'Title': 'foo', 'Date': '01-01-2020'});

main.js

    ipcMain.on('UpdateTheRow', (event, newData)=>{
        knex('Products').where({id: newData.Id}).update({
            title: newData.Title,
            enter_date: newData.Date
        }).then(function (res) {
            console.log(res);
        });
    });

after running update request, console prints the Response , But the renderer refreshes!

in other words when we do something like this:

reaplce console.log in Main.js with:

indexPage.webContents.send("EditedTheRow", res);

and in index.html:

ipc.on('EditedTheRow', (event, response) => {
   alert('Updated');
}

the query works nice but we dont get any alert in Renderer!


Solution

  • Answer:

    The main problem in my case was interference of several frame works!
    I am using sqlite3, so the database saved as a file in my 'root' project folder.
    Along these i am using a "Hot Reload" tool that notices file changes.
    And every time i use a query like Update, Insert and Delete that changes database records, my DB file changes and Hot-reload refreshes the Renderer process!