1
votes

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!

sorry for my poor english.

1

1 Answers

3
votes

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" frame-work that notices file changes.
And every time i use a query like Update, Insert, Delete that changes database, my db file changes and Hot reloader refreshes the Renderer process!