app.js
1.93 KB
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
41
42
43
44
45
46
angular.module('focaSqlite', [])
.factory('focaSqliteService', [
function() {
function error(error) {
console.error(error);
}
return {
openDataBase: function() {
var db = null;
db = window.sqlitePlugin.openDatabase({
name: 'foca.distribuidor',
location: 'default',
});
this.db = db;
var queryCreate = "CREATE TABLE IF NOT EXISTS querys " +
"(route text," +
"type text," +
"body text," +
"response text," +
"PRIMARY KEY(route, body, type))";
this.db.transaction(function(tx) {
tx.executeSql(queryCreate);
}, error);
},
updateQuery: function(route, body, type, response, success) {
var query = 'INSERT OR REPLACE INTO querys (route, type, body, response)' +
"VALUES('" + route + "'" +
", '" + type + "'" +
", '" + body + "'" +
", '" + response + "')";
this.db.transaction(function(tx) {
tx.executeSql(query);
}, error, success)
},
getQuery: function(route, body, type, success) {
var query= "SELECT * FROM querys " +
"WHERE route = '" + route + "'" +
" and body = '" + body + "'" +
" and type = '" + type + "'";
this.db.executeSql(query, [], function(data) {
success(data.rows.item(0).response);
}, error);
}
}
}
]);