Server-Side Scripting/SQL Databases/Node.js (Express)

routes/lesson9.js
"       return result; }

async function countryExists(country) { let sql = ` SELECT EXISTS(               SELECT * FROM Countries                WHERE Country = $country) AS Count; `   let parameters = { $country: country };   let rows = await sqliteAll(sql, parameters); let result = !!rows[0].Count; return result; }

async function insertCountry(country, temperature) { let sql = ` INSERT INTO Countries (Country, Temperature) VALUES($country, $temperature); `   let parameters = { $country: country, $temperature: temperature };   await sqliteRun(sql, parameters); }

async function updateCountry(country, temperature) { let sql = ` UPDATE Countries SET Temperature = $temperature WHERE Country = $country; `   let parameters = { $country: country, $temperature: temperature };   await sqliteRun(sql, parameters); }

async function deleteCountry(country) { let sql = ` DELETE FROM Countries WHERE Country = $country; `   let parameters = { $country: country };   await sqliteRun(sql, parameters); }

async function sqliteAll(sql, parameters) { let promise = new Promise((resolve, reject) => {       let database = new sqlite3.Database(DATABASE);        database.serialize;        database.all(sql, parameters, function(error, rows) { if (error) reject(error); else resolve(rows); });       database.close;    });

let result = await promise; return result; }

async function sqliteRun(sql, parameters) { let promise = new Promise((resolve, reject) => {       let database = new sqlite3.Database(DATABASE);        database.serialize;        database.run(sql, parameters, function(error, rows) { if (error) reject(error); else resolve(rows); });       database.close;    });

let result = await promise; return result; }

module.exports = router;

Try It
See ../../Routes and Templates/Node.js (Express) to create a test environment.