Commit 7329b6ec authored by Zhai, Zirun's avatar Zhai, Zirun

Revert "this reverts commit 131fe6fe."

This reverts commit b2c91a49
parent c9e38d3c
// Unique ID for the className.
var MOUSE_VISITED_CLASSNAME = 'crx_mouse_visited_true';
var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
var srcName;
var db;
// var requestResult;
var dietNum = 0;
......@@ -16,10 +17,10 @@ function dietNumInit() {
dietNum = a + (b << 1) + (c << 2) + (d << 3);
}
// function initialise() {
// var db = new SQL.Database(public.db);
//
// }
function initialize() {
var Uints = new Uint8Array("./public.db");
db = new SqlJs.Database(Uints);
}
// function query(product) {
// const sqlite3 = require('sqlite3').verbose();
......@@ -123,8 +124,6 @@ function dietNumInit() {
function checkAllergen(product) {
var db = new SQL.Database();
var sqlstr = "CREATE TABLE productsingredients (product character varying(255), containsgluten boolean, containsdairy boolean, containscorn boolean, containsmeat boolean);";
sqlstr += "INSERT INTO productsingredients VALUES ('6 Chocolate Fairy Cakes', true, true, true, false);"
db.run(sqlstr);
......@@ -165,6 +164,7 @@ document.addEventListener('mousemove', function (e) {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
// currName = srcElement.srcName;
initialize();
var canEat = checkAllergen('6 Chocolate Fairy Cakes');
if (canEat) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
......@@ -184,5 +184,6 @@ document.addEventListener('mousemove', function (e) {
if(document){
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("Submit").addEventListener("click", dietNumInit);
document.getElementById("Submit").addEventListener("click", initialize);
});
}
../sql.js
\ No newline at end of file
......@@ -896,6 +896,9 @@
"resolved": "https://registry.npmjs.org/sql-js/-/sql-js-0.1.0.tgz",
"integrity": "sha1-OSkM2Rv7yd/8G+Gy+g6WGF7ZQGc="
},
"sql.js": {
"version": "file:sql.js"
},
"sqlite3": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-5.0.0.tgz",
......
......@@ -16,6 +16,7 @@
"dependencies": {
"pg": "^8.3.0",
"sql-js": "^0.1.0",
"sql.js": "file:sql.js",
"sqlite3": "^5.0.0",
"uniq": "^1.0.1",
"xmlhttprequest": "^1.8.0"
......
......@@ -4,7 +4,7 @@
<meta charset = "utf-8"/>
<title> clickerance </title>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="bundle.js"></script>
<script src="content.js"></script>
</head>
<body>
<div class="Title"></div>
......
Subproject commit 592d529c60886aae44389c6b8e00347149083759
var xhr = new XMLHttpRequest();
xhr.open('GET', './public.db', true);
xhr.responseType = 'arraybuffer';
var Uints = new Uint8Array("./public.db");
var db = new SqlJs.Database(Uints);
xhr.onload = function(e) {
var uInt8Array = new Uint8Array(this.response);
var db = new SQL.Database(uInt8Array);
var contents = db.exec("SELECT Containsdairy cd, Containsmeat cm, Containscorn cc, Containsgluten cg FROM productsIngredients WHERE Product = 'Waitrose Millionaire Bites'");
// contents is now [{columns:['col1','col2',...], values:[[first row], [second row], ...]}]
};
var sqlstr = "CREATE TABLE productsingredients (product character varying(255), containsgluten boolean, containsdairy boolean, containscorn boolean, containsmeat boolean);";
sqlstr += "INSERT INTO productsingredients VALUES ('6 Chocolate Fairy Cakes', true, true, true, false);"
db.run(sqlstr);
let sql = `SELECT containsdairy cd,
containsmeat cm,
containscorn cc,
containsgluten cg
FROM productsIngredients
WHERE product=:prod`;
// WHERE Product = ` + product
var stmt = db.prepare(sql);
var result = stmt.getAsObject({':prod' : product});
console.log(cc);
console.log(result);
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