Commit cb2c4e85e48710e8b33df855693e166fe7cfee24
1 parent
67f1e4317d
Exists in
master
code review
Showing
1 changed file
with
3 additions
and
7 deletions
Show diff stats
src/js/app.js
1 | angular.module('focaSqlite', []) | 1 | angular.module('focaSqlite', []) |
2 | .factory('focaSqliteService', [ | 2 | .factory('focaSqliteService', [ |
3 | function() { | 3 | function() { |
4 | function error(error) { | 4 | function error(error) { |
5 | console.log(error); | 5 | console.error(error); |
6 | } | 6 | } |
7 | return { | 7 | return { |
8 | openDataBase: function() { | 8 | openDataBase: function() { |
9 | var db = null; | 9 | var db = null; |
10 | db = window.sqlitePlugin.openDatabase({ | 10 | db = window.sqlitePlugin.openDatabase({ |
11 | name: 'foca.distribuidor', | 11 | name: 'foca.distribuidor', |
12 | location: 'default', | 12 | location: 'default', |
13 | }); | 13 | }); |
14 | this.db = db; | 14 | this.db = db; |
15 | var queryCreate = "CREATE TABLE IF NOT EXISTS querys " + | 15 | var queryCreate = "CREATE TABLE IF NOT EXISTS querys " + |
16 | "(route text," + | 16 | "(route text," + |
17 | "type text," + | 17 | "type text," + |
18 | "body text," + | 18 | "body text," + |
19 | "response text," + | 19 | "response text," + |
20 | "PRIMARY KEY(route, body, type))"; | 20 | "PRIMARY KEY(route, body, type))"; |
21 | this.db.transaction(function(tx) { | 21 | this.db.transaction(function(tx) { |
22 | tx.executeSql(queryCreate); | 22 | tx.executeSql(queryCreate); |
23 | }, function(error) { | 23 | }, error); |
24 | console.log(error); | ||
25 | }); | ||
26 | }, | 24 | }, |
27 | updateQuery: function(route, body, type, response, success) { | 25 | updateQuery: function(route, body, type, response, success) { |
28 | var query = 'INSERT OR REPLACE INTO querys (route, type, body, response)' + | 26 | var query = 'INSERT OR REPLACE INTO querys (route, type, body, response)' + |
29 | "VALUES('" + route + "'" + | 27 | "VALUES('" + route + "'" + |
30 | ", '" + type + "'" + | 28 | ", '" + type + "'" + |
31 | ", '" + body + "'" + | 29 | ", '" + body + "'" + |
32 | ", '" + response + "')"; | 30 | ", '" + response + "')"; |
33 | this.db.transaction(function(tx) { | 31 | this.db.transaction(function(tx) { |
34 | tx.executeSql(query); | 32 | tx.executeSql(query); |
35 | }, function(error) { | 33 | }, error, success) |
36 | console.log(error); | ||
37 | }, success) | ||
38 | }, | 34 | }, |
39 | getQuery: function(route, body, type, success) { | 35 | getQuery: function(route, body, type, success) { |
40 | var query= "SELECT * FROM querys " + | 36 | var query= "SELECT * FROM querys " + |
41 | "WHERE route = '" + route + "'" + | 37 | "WHERE route = '" + route + "'" + |
42 | " and body = '" + body + "'" + | 38 | " and body = '" + body + "'" + |
43 | " and type = '" + type + "'"; | 39 | " and type = '" + type + "'"; |
44 | this.db.executeSql(query, [], function(data) { | 40 | this.db.executeSql(query, [], function(data) { |
45 | success(data.rows.item(0).response); | 41 | success(data.rows.item(0).response); |
46 | }, error); | 42 | }, error); |
47 | } | 43 | } |
48 | } | 44 | } |
49 | } | 45 | } |
50 | ]); | 46 | ]); |
51 | 47 |