· 8 years ago · May 28, 2018, 08:34 AM
1
2
3var Config = Class.create(dbSQLite, {
4
5 table: "Config",
6
7 initialize:function() {
8 this.db = "DatabaseName.db";
9 this.bootstrap();
10 },
11
12 bootstrap:function() {
13 var createSQL = "CREATE TABLE IF NOT EXISTS "+ this.table +" (";
14 createSQL += "name TEXT UNIQUE, ";
15 createSQL += "value TEXT";
16 createSQL += ")";
17
18 return this.execute(createSQL);
19 },
20
21 get:function(key) {
22 var sql = "SELECT * FROM "+ this.table +" WHERE name = :name";
23 return this.execute(sql, {
24 ":name" : key
25 });
26 },
27
28 set:function(key, value) {
29 var sql = (this.get(key).data === null)
30 ? "INSERT INTO "+ this.table +" (name, value) VALUES (:name, :value)"
31 : "UPDATE "+ this.table +" SET name = :value WHERE name = :name";
32
33 return this.execute(sql, {
34 ":name" : key,
35 ":value" : value
36 });
37 }
38
39});