Commit 37672aad authored by Zhai Zirun's avatar Zhai Zirun

added sql.js submodule

parent b74dd250
[submodule "sql.js"]
path = sql.js
url = https://github.com/sql-js/sql.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Bundle = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
// 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 requestResult;
// var requestResult;
var dietNum = 0;
......@@ -43,57 +43,55 @@ function query(product) {
if (!row) {
return console.error(`No product found with the name ${product}`);
}
return row.cg
//return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
});
db.close();
}
function callBack(canEat) {
if (canEat == undefined) {
requestResult = true;
} else if (canEat == "0") {
requestResult = true;
} else if (canEat == "1") {
requestResult = true;
} else if (canEat == "Could not connect") {
result = true;
} else if (canEat == 1) {
requestResult = true;
} else if (canEat == '1') {
requestResult = true;
}
}
function checkAllergen(product) {
request(product);
return requestResult;
}
function checkAllergen(product) {
var xhr = new XMLHttpRequest();
var result;
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var canEat = this.responseText;
if (canEat == undefined) {
result = false;
} else if (canEat == "0") {
result = false;
} else if (canEat == "1") {
result = true;
} else if (canEat == "Could not connect") {
result = false;
}
}
};
xhr.open("GET", "script.php?q="+product, true);
xhr.send();
return result;
}
// function callBack(canEat) {
// if (canEat == undefined) {
// requestResult = true;
// } else if (canEat == "0") {
// requestResult = true;
// } else if (canEat == "1") {
// requestResult = true;
// } else if (canEat == "Could not connect") {
// result = true;
// } else if (canEat == 1) {
// requestResult = true;
// } else if (canEat == '1') {
// requestResult = true;
// }
// }
// function checkAllergen(product) {
// request(product);
// return requestResult;
// }
// function checkAllergen(product) {
// var xhr = new XMLHttpRequest();
// var result;
// xhr.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// var canEat = this.responseText;
// if (canEat == undefined) {
// result = false;
// } else if (canEat == "0") {
// result = false;
// } else if (canEat == "1") {
// result = true;
// } else if (canEat == "Could not connect") {
// result = false;
// }
// }
// };
// xhr.open("GET", "script.php?q="+product, true);
// xhr.send();
// return result;
// }
// Previous dom, that we want to track, so we can remove the previous styling.
......@@ -20219,5 +20217,4 @@ arguments[4][86][0].apply(exports,arguments)
arguments[4][87][0].apply(exports,arguments)
},{"dup":87}],129:[function(require,module,exports){
arguments[4][88][0].apply(exports,arguments)
},{"./support/isBuffer":128,"_process":102,"dup":88,"inherits":127}]},{},[1])(1)
});
},{"./support/isBuffer":128,"_process":102,"dup":88,"inherits":127}]},{},[1]);
......@@ -4,7 +4,7 @@ var MOUSE_VISITED_CLASSNAME_FALSE = 'crx_mouse_visited_false';
var srcName;
var requestResult;
// var requestResult;
var dietNum = 0;
......@@ -16,83 +16,81 @@ function dietNumInit() {
dietNum = a + (b << 1) + (c << 2) + (d << 3);
}
function query(product) {
const sqlite3 = require('sqlite3').verbose();
let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
if (err) {
console.error('Error connecting to database');
}
console.log('Connected to the in-memory SQlite database.');
});
let sql = `SELECT Containsdairy cd,
Containsmeat cm,
Containscorn cc,
Containsgluten cg
FROM productsIngredients
WHERE Product = ?`;
// function query(product) {
// const sqlite3 = require('sqlite3').verbose();
// let db = new sqlite3.Database('./public.db', sqlite3.OPEN_READONLY, (err) => {
// if (err) {
// console.error('Error connecting to database');
// }
// console.log('Connected to the in-memory SQlite database.');
// });
// let sql = `SELECT Containsdairy cd,
// Containsmeat cm,
// Containscorn cc,
// Containsgluten cg
// FROM productsIngredients
// WHERE Product = ?`;
db.get(sql, product, (err, row) => {
if (err) {
return console.error('Error querying database');
}
if (!row) {
return console.error(`No product found with the name ${product}`);
}
return row.cg
//return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
});
db.close();
}
function callBack(canEat) {
if (canEat == undefined) {
requestResult = true;
} else if (canEat == "0") {
requestResult = true;
} else if (canEat == "1") {
requestResult = true;
} else if (canEat == "Could not connect") {
result = true;
} else if (canEat == 1) {
requestResult = true;
} else if (canEat == '1') {
requestResult = true;
}
}
function checkAllergen(product) {
request(product);
return requestResult;
}
function checkAllergen(product) {
var xhr = new XMLHttpRequest();
var result;
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var canEat = this.responseText;
if (canEat == undefined) {
result = false;
} else if (canEat == "0") {
result = false;
} else if (canEat == "1") {
result = true;
} else if (canEat == "Could not connect") {
result = false;
}
}
};
xhr.open("GET", "script.php?q="+product, true);
xhr.send();
return result;
}
// db.get(sql, product, (err, row) => {
// if (err) {
// return console.error('Error querying database');
// }
// if (!row) {
// return console.error(`No product found with the name ${product}`);
// }
// return !((cd && (1 && dietNum)) || (cm && (2 && dietNum)) || (cc && (4 && dietNum)) || (cg && (8 && dietNum)))
// });
// db.close();
// }
// function callBack(canEat) {
// if (canEat == undefined) {
// requestResult = true;
// } else if (canEat == "0") {
// requestResult = true;
// } else if (canEat == "1") {
// requestResult = true;
// } else if (canEat == "Could not connect") {
// result = true;
// } else if (canEat == 1) {
// requestResult = true;
// } else if (canEat == '1') {
// requestResult = true;
// }
// }
// function checkAllergen(product) {
// request(product);
// return requestResult;
// }
// function checkAllergen(product) {
// var xhr = new XMLHttpRequest();
// var result;
// xhr.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// var canEat = this.responseText;
// if (canEat == undefined) {
// result = false;
// } else if (canEat == "0") {
// result = false;
// } else if (canEat == "1") {
// result = true;
// } else if (canEat == "Could not connect") {
// result = false;
// }
// }
// };
// xhr.open("GET", "script.php?q="+product, true);
// xhr.send();
// return result;
// }
// Previous dom, that we want to track, so we can remove the previous styling.
......@@ -117,10 +115,10 @@ document.addEventListener('mousemove', function (e) {
// srcElement.classList.add(MOUSE_VISITED_CLASSNAME);
// }
// currName = srcElement.srcName;
if (query(srcName)) {
if (true) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME); //changes outline of pic
}
if (!query(srcName)) {
if (!true) {
srcElement.classList.add(MOUSE_VISITED_CLASSNAME_FALSE);
}
//TODO: modify behaviour according to different allergens
......
{
"node": true,
"browser": false,
"esnext": true,
"bitwise": false,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"immed": true,
"indent": 2,
"latedef": true,
"laxbreak": true,
"newcap": true,
"noarg": true,
"quotmark": "double",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"define": false
}
}
example
tests
autotest.watchr
Copyright (c) 2010 passive.ly LLC
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
# node-XMLHttpRequest #
node-XMLHttpRequest is a wrapper for the built-in http client to emulate the
browser XMLHttpRequest object.
This can be used with JS designed for browsers to improve reuse of code and
allow the use of existing libraries.
Note: This library currently conforms to [XMLHttpRequest 1](http://www.w3.org/TR/XMLHttpRequest/). Version 2.0 will target [XMLHttpRequest Level 2](http://www.w3.org/TR/XMLHttpRequest2/).
## Usage ##
Here's how to include the module in your project and use as the browser-based
XHR object.
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
Note: use the lowercase string "xmlhttprequest" in your require(). On
case-sensitive systems (eg Linux) using uppercase letters won't work.
## Versions ##
Prior to 1.4.0 version numbers were arbitrary. From 1.4.0 on they conform to
the standard major.minor.bugfix. 1.x shouldn't necessarily be considered
stable just because it's above 0.x.
Since the XMLHttpRequest API is stable this library's API is stable as
well. Major version numbers indicate significant core code changes.
Minor versions indicate minor core code changes or better conformity to
the W3C spec.
## License ##
MIT license. See LICENSE for full details.
## Supports ##
* Async and synchronous requests
* GET, POST, PUT, and DELETE requests
* All spec methods (open, send, abort, getRequestHeader,
getAllRequestHeaders, event methods)
* Requests to all domains
## Known Issues / Missing Features ##
For a list of open issues or to report your own visit the [github issues
page](https://github.com/driverdan/node-XMLHttpRequest/issues).
* Local file access may have unexpected results for non-UTF8 files
* Synchronous requests don't set headers properly
* Synchronous requests freeze node while waiting for response (But that's what you want, right? Stick with async!).
* Some events are missing, such as abort
* Cookies aren't persisted between requests
* Missing XML support
This diff is collapsed.
{
"_from": "xmlhttprequest",
"_id": "xmlhttprequest@1.8.0",
"_inBundle": false,
"_integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=",
"_location": "/xmlhttprequest",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "xmlhttprequest",
"name": "xmlhttprequest",
"escapedName": "xmlhttprequest",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
"_shasum": "67fe075c5c24fef39f9d65f5f7b7fe75171968fc",
"_spec": "xmlhttprequest",
"_where": "/Users/zirun/Documents/NON-SCHOOL PROJECTS/chrome-groceries-extension",
"author": {
"name": "Dan DeFelippi",
"url": "http://driverdan.com"
},
"bugs": {
"url": "http://github.com/driverdan/node-XMLHttpRequest/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "XMLHttpRequest for Node",
"directories": {
"lib": "./lib",
"example": "./example"
},
"engines": {
"node": ">=0.4.0"
},
"homepage": "https://github.com/driverdan/node-XMLHttpRequest#readme",
"keywords": [
"xhr",
"ajax"
],
"license": "MIT",
"main": "./lib/XMLHttpRequest.js",
"name": "xmlhttprequest",
"repository": {
"type": "git",
"url": "git://github.com/driverdan/node-XMLHttpRequest.git"
},
"version": "1.8.0"
}
......@@ -1048,6 +1048,11 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"xmlhttprequest": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw="
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
......
......@@ -16,6 +16,7 @@
"dependencies": {
"pg": "^8.3.0",
"sqlite3": "^5.0.0",
"uniq": "^1.0.1"
"uniq": "^1.0.1",
"xmlhttprequest": "^1.8.0"
}
}
Subproject commit 592d529c60886aae44389c6b8e00347149083759
var xhr = new XMLHttpRequest();
xhr.open('GET', './public.db', true);
xhr.responseType = 'arraybuffer';
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], ...]}]
};
console.log(cc);
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