Why does background-color change?

I’m new to electron.

A very simple test with css background-color set to dark gray becomes white when running this in index.html

let file = "art.db";
let db = new sqlite3.Database(file);
db.all("SELECT name FROM prints", function (err, rows) {
  rows.forEach(function (row) {
    document.write(row.name);
  })
});
db.close();

But not with document.write(“hello”)

Why?

So when you have a static variable the background image doesn’t change to white?

It’s just a color but you’re right. I’ve discovered that it must be because the data is loaded before the window is ready. I can load other data but not from sqlite. If keep the data in a variable instead of writing it directly and I load it after with a function onclick it’s fine. How do I load the variable automatically, like a window.onload?

let sqlite3 = require('sqlite3').verbose();

let file = "art.db";
let db = new sqlite3.Database(file);
let artwork = '';
db.all("SELECT name FROM prints", function (err, rows) {
  rows.forEach(function (row) {
    artwork += row.name;
    // document.write(row.name);
  })
});

var fruits = ["apple", "orange", "banana"];
var test = '';
fruits.forEach(function (item) {
  test += item;
})


db.close();

document.querySelector("#artlist").innerHTML = test;

function listPrints() {
  document.querySelector("#artlist").innerHTML = artwork;
}

UPDATE:
Finding some answers here " Developing ElectronJS applications with SQLite3" https://youtu.be/c76FTxLRwAw
I’ll look into knexjs and ipcMain.

Maybe try this:

document.addEventListener("DOMContentLoaded",function(){

    //here code
});

You are wrapping all your code at not executing any of it until the DOM is loaded.

1 Like