Commit 645df31b authored by Zhai Zirun's avatar Zhai Zirun

got database queries to work in isolation

parent 0adc6718
......@@ -6,20 +6,28 @@ var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
function query(product) {
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database(':memory:', sqlite3.OPEN_READONLY, (err) => {
let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
if (err) {
console.error(err.message);
}
}); //TODO: replace memory with './db/database.db' ie the db location
console.log('Connected to the in-memory SQlite database.');
});
let sql = `SELECT Containsgluten, Containsdairy, Containscorn, Containsmeat FROM productsIngredients WHERE Product = ?`;
let sql = `SELECT Containsgluten cg,
Containsdairy cd,
Containscorn cc,
Containsmeat cm
FROM productsIngredients
WHERE Product = ?`;
db.get(sql, product, (err, row) => {
if (err) {
return console.error(err.message);
}
requestResult = canEat;
//TODO: uh idk where to get canEat from from the database help blease
return row
? console.log(row.cg)
: console.log(`No product found with the name ${product}`);
});
db.close();
}
......
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
if (err) {
console.error(err.message);
}
console.log('Connected to the in-memory SQlite database.');
});
let product = 'Waitrose Millionaire Bites'
let sql = `SELECT Containsgluten cg,
Containsdairy cd,
Containscorn cc,
Containsmeat cm
FROM productsIngredients
WHERE Product = ?`;
db.get(sql, product, (err, row) => {
if (err) {
return console.error(err.message);
}
return row
? console.log(row.cg)
: console.log(`No product found with the name ${product}`);
});
db.close();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment