-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite.js
40 lines (32 loc) · 1.01 KB
/
sqlite.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module.exports = {
filename: "db.sqlite",
getDb: function(jf, sqlite3){
var exists = jf.existsSync(this.filename);
var db = new sqlite3.Database(this.filename);
db.serialize(function() {
if(!exists) {
db.run("CREATE TABLE suggestions (name TEXT PRIMARY KEY, url TEXT)", function(e){
console.log(e);
}, function(e){
console.log(e);
});
}
});
return db;
},
save_suggestion: function(jf, sqlite3, bankName, bankurl){
var db = this.getDb(jf, sqlite3);
db.serialize(function(){
db.run("insert or replace into suggestions (name, url) values ('"+bankName +"','" + bankurl + "')");
});
},
get_suggestion: function(jf, sqlite3, bankName, callback){
var db = this.getDb(jf, sqlite3);
var result = null;
db.serialize(function() {
db.get("SELECT name, url FROM suggestions where name like '" + bankName +"'", [], function(err, row) {
callback(row ? row.url : null);
});
});
},
};