I managed to install sqlite in electron but now i have the problem of how to call sql queries in my html file. I tried using the following code in index.html
<script type='text/javascript' src='query_table.js'></script>
in query_table.js:
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('db.sqlite');
function hello() {
console.log("sssssssssssssssssssssssssssssssssssssssssssss");
db.serialize(() => {
db.each("SELECT * FROM events", (err, row) => {
console.log(row.id + ": " + row.data);
});
});
db.close();
}
but I get this error when I launch my app:
Uncaught ReferenceError: require is not defined
what is the right way to call functions using the db? i would like to create several js files based on the various models i have (tables in my db). I would like to import a model to run sql queries based on where I am within my app. How should this be done? What is the best practice?