[Chartjs]-Cannot call a function in Javascript – Chart.js

1👍

Your delData function is not waiting to delete the item from the database before calling the refreshData function, use:

function delData() {
  var data_firstName = document.getElementById('firstName').value;

  const sqlite3 = require('sqlite3').verbose();
  let db = new sqlite3.Database('./data.db');
  db.run(`DELETE FROM Info WHERE firstName = '${data_firstName}';`, function(err, row) {
    db.close();
    refreshData();
  });
}

So the refresh will run after the delete.

You can achieve the same results using ES6 async/await:

async function delData() {
  var data_firstName = document.getElementById('firstName').value;

  const sqlite3 = require('sqlite3').verbose();
  let db = new sqlite3.Database('./data.db');
  await db.run(`DELETE FROM Info WHERE firstName = '${data_firstName}';`);
  db.close();
  refreshData();
}

This will wait until the db command complete, then continue the execution.

Leave a comment