db-wrapper 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/db-wrapper.umd.js +640 -951
- package/bundles/db-wrapper.umd.js.map +1 -1
- package/bundles/db-wrapper.umd.min.js +15 -1
- package/bundles/db-wrapper.umd.min.js.map +1 -1
- package/db-wrapper.metadata.json +1 -1
- package/esm2015/db-wrapper.js +2 -6
- package/esm2015/lib/db-wrapper.models.js +45 -206
- package/esm2015/lib/db-wrapper.module.js +10 -16
- package/esm2015/lib/db-wrapper.service.js +110 -481
- package/esm2015/lib/window.service.js +8 -16
- package/esm2015/public-api.js +4 -8
- package/esm5/db-wrapper.js +2 -6
- package/esm5/lib/db-wrapper.models.js +45 -206
- package/esm5/lib/db-wrapper.module.js +9 -20
- package/esm5/lib/db-wrapper.service.js +132 -593
- package/esm5/lib/window.service.js +6 -15
- package/esm5/public-api.js +4 -8
- package/fesm2015/db-wrapper.js +169 -539
- package/fesm2015/db-wrapper.js.map +1 -1
- package/fesm5/db-wrapper.js +189 -653
- package/fesm5/db-wrapper.js.map +1 -1
- package/lib/db-wrapper.service.d.ts +4 -2
- package/lib/window.service.d.ts +1 -1
- package/package.json +7 -7
|
@@ -1,942 +1,666 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define('db-wrapper', ['exports', '@angular/core'], factory) :
|
|
4
|
-
(factory(
|
|
5
|
-
}(this, (function (exports,core) { 'use strict';
|
|
4
|
+
(global = global || self, factory(global['db-wrapper'] = {}, global.ng.core));
|
|
5
|
+
}(this, (function (exports, core) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
10
|
-
this file except in compliance with the License. You may obtain a copy of the
|
|
11
|
-
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
16
|
-
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
20
|
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/* global Reflect, Promise */
|
|
22
|
+
|
|
23
|
+
var extendStatics = function(d, b) {
|
|
24
|
+
extendStatics = Object.setPrototypeOf ||
|
|
25
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
26
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
27
|
+
return extendStatics(d, b);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function __extends(d, b) {
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() { this.constructor = d; }
|
|
33
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var __assign = function() {
|
|
37
|
+
__assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
25
41
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
return t;
|
|
43
|
+
};
|
|
44
|
+
return __assign.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
50
|
+
t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
52
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
54
|
+
t[p[i]] = s[p[i]];
|
|
31
55
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
62
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function __param(paramIndex, decorator) {
|
|
67
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function __metadata(metadataKey, metadataValue) {
|
|
71
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
75
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
76
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
77
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
78
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
79
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
36
80
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
81
|
});
|
|
38
82
|
}
|
|
83
|
+
|
|
39
84
|
function __generator(thisArg, body) {
|
|
40
|
-
var _ = { label: 0, sent: function
|
|
41
|
-
|
|
42
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
|
85
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
86
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
43
87
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
44
88
|
function step(op) {
|
|
45
|
-
if (f)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
case 5:
|
|
62
|
-
_.label++;
|
|
63
|
-
y = op[1];
|
|
64
|
-
op = [0];
|
|
65
|
-
continue;
|
|
66
|
-
case 7:
|
|
67
|
-
op = _.ops.pop();
|
|
68
|
-
_.trys.pop();
|
|
69
|
-
continue;
|
|
70
|
-
default:
|
|
71
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
72
|
-
_ = 0;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
|
76
|
-
_.label = op[1];
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
80
|
-
_.label = t[1];
|
|
81
|
-
t = op;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
if (t && _.label < t[2]) {
|
|
85
|
-
_.label = t[2];
|
|
86
|
-
_.ops.push(op);
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
if (t[2])
|
|
90
|
-
_.ops.pop();
|
|
91
|
-
_.trys.pop();
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
op = body.call(thisArg, _);
|
|
89
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
90
|
+
while (_) try {
|
|
91
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
92
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
93
|
+
switch (op[0]) {
|
|
94
|
+
case 0: case 1: t = op; break;
|
|
95
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
96
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
97
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
98
|
+
default:
|
|
99
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
100
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
101
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
102
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
103
|
+
if (t[2]) _.ops.pop();
|
|
104
|
+
_.trys.pop(); continue;
|
|
95
105
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
op = body.call(thisArg, _);
|
|
107
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
108
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function __createBinding(o, m, k, k2) {
|
|
113
|
+
if (k2 === undefined) k2 = k;
|
|
114
|
+
o[k2] = m[k];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function __exportStar(m, exports) {
|
|
118
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function __values(o) {
|
|
122
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
123
|
+
if (m) return m.call(o);
|
|
124
|
+
if (o && typeof o.length === "number") return {
|
|
125
|
+
next: function () {
|
|
126
|
+
if (o && i >= o.length) o = void 0;
|
|
127
|
+
return { value: o && o[i++], done: !o };
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function __read(o, n) {
|
|
134
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
135
|
+
if (!m) return o;
|
|
136
|
+
var i = m.call(o), r, ar = [], e;
|
|
137
|
+
try {
|
|
138
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
139
|
+
}
|
|
140
|
+
catch (error) { e = { error: error }; }
|
|
141
|
+
finally {
|
|
142
|
+
try {
|
|
143
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
144
|
+
}
|
|
145
|
+
finally { if (e) throw e.error; }
|
|
146
|
+
}
|
|
147
|
+
return ar;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function __spread() {
|
|
151
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
152
|
+
ar = ar.concat(__read(arguments[i]));
|
|
153
|
+
return ar;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function __spreadArrays() {
|
|
157
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
158
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
159
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
160
|
+
r[k] = a[j];
|
|
161
|
+
return r;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
function __await(v) {
|
|
165
|
+
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function __asyncGenerator(thisArg, _arguments, generator) {
|
|
169
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
170
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
171
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
172
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
173
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
174
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
175
|
+
function fulfill(value) { resume("next", value); }
|
|
176
|
+
function reject(value) { resume("throw", value); }
|
|
177
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function __asyncDelegator(o) {
|
|
181
|
+
var i, p;
|
|
182
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
|
183
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function __asyncValues(o) {
|
|
187
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
188
|
+
var m = o[Symbol.asyncIterator], i;
|
|
189
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
190
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
191
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function __makeTemplateObject(cooked, raw) {
|
|
195
|
+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
|
196
|
+
return cooked;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function __importStar(mod) {
|
|
200
|
+
if (mod && mod.__esModule) return mod;
|
|
201
|
+
var result = {};
|
|
202
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
203
|
+
result.default = mod;
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function __importDefault(mod) {
|
|
208
|
+
return (mod && mod.__esModule) ? mod : { default: mod };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function __classPrivateFieldGet(receiver, privateMap) {
|
|
212
|
+
if (!privateMap.has(receiver)) {
|
|
213
|
+
throw new TypeError("attempted to get private field on non-instance");
|
|
106
214
|
}
|
|
215
|
+
return privateMap.get(receiver);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function __classPrivateFieldSet(receiver, privateMap, value) {
|
|
219
|
+
if (!privateMap.has(receiver)) {
|
|
220
|
+
throw new TypeError("attempted to set private field on non-instance");
|
|
221
|
+
}
|
|
222
|
+
privateMap.set(receiver, value);
|
|
223
|
+
return value;
|
|
107
224
|
}
|
|
108
225
|
|
|
109
|
-
/**
|
|
110
|
-
* @fileoverview added by tsickle
|
|
111
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
112
|
-
*/
|
|
113
226
|
var WindowService = /** @class */ (function () {
|
|
114
227
|
function WindowService() {
|
|
115
228
|
}
|
|
116
229
|
Object.defineProperty(WindowService.prototype, "nativeWindow", {
|
|
117
|
-
get:
|
|
118
|
-
* @return {?}
|
|
119
|
-
*/ function () {
|
|
230
|
+
get: function () {
|
|
120
231
|
return _window();
|
|
121
232
|
},
|
|
122
233
|
enumerable: true,
|
|
123
234
|
configurable: true
|
|
124
235
|
});
|
|
125
|
-
WindowService
|
|
126
|
-
|
|
127
|
-
];
|
|
236
|
+
WindowService = __decorate([
|
|
237
|
+
core.Injectable()
|
|
238
|
+
], WindowService);
|
|
128
239
|
return WindowService;
|
|
129
240
|
}());
|
|
130
|
-
/**
|
|
131
|
-
* @return {?}
|
|
132
|
-
*/
|
|
133
241
|
function _window() {
|
|
134
242
|
// Return the global native browser window object
|
|
135
243
|
return typeof window !== 'undefined' ? window : undefined;
|
|
136
244
|
}
|
|
137
245
|
|
|
138
|
-
/**
|
|
139
|
-
* @fileoverview added by tsickle
|
|
140
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
141
|
-
*/
|
|
142
246
|
var DbWrapperService = /** @class */ (function () {
|
|
143
247
|
function DbWrapperService(dbConfig, dbSchema) {
|
|
144
248
|
var _this = this;
|
|
145
249
|
this._dbName = dbConfig.dbName;
|
|
146
250
|
this._location = dbConfig.location || 'default';
|
|
147
251
|
this._iosDatabaseLocation = dbConfig.iosDatabaseLocation || 'Library';
|
|
148
|
-
/** @type {?} */
|
|
149
252
|
var window = (new WindowService()).nativeWindow;
|
|
150
253
|
if (dbSchema) {
|
|
151
254
|
this.schema = dbSchema;
|
|
152
255
|
}
|
|
153
|
-
this._readyPromise = new Promise((
|
|
154
|
-
* @param {?} resolve
|
|
155
|
-
* @param {?} reject
|
|
156
|
-
* @return {?}
|
|
157
|
-
*/function (resolve, reject) {
|
|
256
|
+
this._readyPromise = new Promise(function (resolve, reject) {
|
|
158
257
|
if (typeof window.cordova === 'undefined') {
|
|
159
|
-
setTimeout((
|
|
160
|
-
|
|
161
|
-
*/function () {
|
|
162
|
-
_this.init(dbSchema).then(( /**
|
|
163
|
-
* @return {?}
|
|
164
|
-
*/function () {
|
|
258
|
+
setTimeout(function () {
|
|
259
|
+
_this.init(dbSchema).then(function () {
|
|
165
260
|
resolve();
|
|
166
|
-
})
|
|
167
|
-
.catch((
|
|
168
|
-
* @param {?} err
|
|
169
|
-
* @return {?}
|
|
170
|
-
*/function (err) {
|
|
261
|
+
})
|
|
262
|
+
.catch(function (err) {
|
|
171
263
|
reject(err);
|
|
172
|
-
})
|
|
173
|
-
}
|
|
264
|
+
});
|
|
265
|
+
}, 500);
|
|
174
266
|
}
|
|
175
267
|
else {
|
|
176
|
-
document.addEventListener('deviceready', (
|
|
177
|
-
* @return {?}
|
|
178
|
-
*/function () {
|
|
268
|
+
document.addEventListener('deviceready', function () {
|
|
179
269
|
console.log('dbWrapper: device ready.');
|
|
180
|
-
_this.initDevice(dbSchema).then((
|
|
181
|
-
* @return {?}
|
|
182
|
-
*/function () { return resolve(); })).catch(( /**
|
|
183
|
-
* @param {?} err
|
|
184
|
-
* @return {?}
|
|
185
|
-
*/function (err) { return reject(err); }));
|
|
186
|
-
}));
|
|
187
|
-
}
|
|
188
|
-
}));
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* @return {?}
|
|
192
|
-
*/
|
|
193
|
-
DbWrapperService.prototype.ready = /**
|
|
194
|
-
* @return {?}
|
|
195
|
-
*/
|
|
196
|
-
function () {
|
|
197
|
-
return this._readyPromise;
|
|
198
|
-
};
|
|
199
|
-
/**
|
|
200
|
-
* @param {?} dbSchema
|
|
201
|
-
* @return {?}
|
|
202
|
-
*/
|
|
203
|
-
DbWrapperService.prototype.initDevice = /**
|
|
204
|
-
* @param {?} dbSchema
|
|
205
|
-
* @return {?}
|
|
206
|
-
*/
|
|
207
|
-
function (dbSchema) {
|
|
208
|
-
var _this = this;
|
|
209
|
-
/** @type {?} */
|
|
210
|
-
var window = (new WindowService()).nativeWindow;
|
|
211
|
-
return new Promise(( /**
|
|
212
|
-
* @param {?} resolve
|
|
213
|
-
* @param {?} reject
|
|
214
|
-
* @return {?}
|
|
215
|
-
*/function (resolve, reject) {
|
|
216
|
-
_this.db = window.sqlitePlugin.openDatabase({
|
|
217
|
-
name: _this._dbName,
|
|
218
|
-
location: _this._location,
|
|
219
|
-
androidLockWorkaround: 1
|
|
270
|
+
_this.initDevice(dbSchema).then(function () { return resolve(); }).catch(function (err) { return reject(err); });
|
|
220
271
|
});
|
|
221
|
-
if (dbSchema) {
|
|
222
|
-
_this.generate(dbSchema).catch(( /**
|
|
223
|
-
* @param {?} err
|
|
224
|
-
* @return {?}
|
|
225
|
-
*/function (err) {
|
|
226
|
-
reject(err);
|
|
227
|
-
})).then(( /**
|
|
228
|
-
* @return {?}
|
|
229
|
-
*/function () { resolve(); }));
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
resolve();
|
|
233
|
-
}
|
|
234
|
-
}));
|
|
235
|
-
};
|
|
236
|
-
/**
|
|
237
|
-
* @param {?} dbSchema
|
|
238
|
-
* @return {?}
|
|
239
|
-
*/
|
|
240
|
-
DbWrapperService.prototype.init = /**
|
|
241
|
-
* @param {?} dbSchema
|
|
242
|
-
* @return {?}
|
|
243
|
-
*/
|
|
244
|
-
function (dbSchema) {
|
|
245
|
-
var _this = this;
|
|
246
|
-
/** @type {?} */
|
|
247
|
-
var window = (new WindowService()).nativeWindow;
|
|
248
|
-
return new Promise(( /**
|
|
249
|
-
* @param {?} resolve
|
|
250
|
-
* @param {?} reject
|
|
251
|
-
* @return {?}
|
|
252
|
-
*/function (resolve, reject) {
|
|
253
|
-
_this.db = window.openDatabase(_this._dbName, '1.0', 'database', -1);
|
|
254
|
-
if (dbSchema) {
|
|
255
|
-
_this.generate(dbSchema).catch(( /**
|
|
256
|
-
* @param {?} err
|
|
257
|
-
* @return {?}
|
|
258
|
-
*/function (err) {
|
|
259
|
-
reject(err);
|
|
260
|
-
})).then(( /**
|
|
261
|
-
* @return {?}
|
|
262
|
-
*/function () {
|
|
263
|
-
resolve();
|
|
264
|
-
}));
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
resolve();
|
|
268
|
-
}
|
|
269
|
-
}));
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* @param {?} schema
|
|
273
|
-
* @return {?}
|
|
274
|
-
*/
|
|
275
|
-
DbWrapperService.prototype.generate = /**
|
|
276
|
-
* @param {?} schema
|
|
277
|
-
* @return {?}
|
|
278
|
-
*/
|
|
279
|
-
function (schema) {
|
|
280
|
-
var _this = this;
|
|
281
|
-
/** @type {?} */
|
|
282
|
-
var sentences = [];
|
|
283
|
-
this.schema = schema;
|
|
284
|
-
if (schema.tables) {
|
|
285
|
-
schema.tables.forEach(( /**
|
|
286
|
-
* @param {?} table
|
|
287
|
-
* @return {?}
|
|
288
|
-
*/function (table) {
|
|
289
|
-
sentences.push(_this.createTable(table));
|
|
290
|
-
}));
|
|
291
272
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
DbWrapperService.prototype.ready = function () {
|
|
276
|
+
return this._readyPromise;
|
|
277
|
+
};
|
|
278
|
+
DbWrapperService.prototype.initDevice = function (dbSchema) {
|
|
279
|
+
var _this = this;
|
|
280
|
+
var window = (new WindowService()).nativeWindow;
|
|
281
|
+
return new Promise(function (resolve, reject) {
|
|
282
|
+
_this.db = window.sqlitePlugin.openDatabase({
|
|
283
|
+
name: _this._dbName,
|
|
284
|
+
location: _this._location,
|
|
285
|
+
androidLockWorkaround: 1
|
|
286
|
+
});
|
|
287
|
+
if (dbSchema) {
|
|
288
|
+
_this.generate(dbSchema).catch(function (err) {
|
|
289
|
+
reject(err);
|
|
290
|
+
}).then(function () { resolve(); });
|
|
299
291
|
}
|
|
300
|
-
|
|
301
|
-
|
|
292
|
+
else {
|
|
293
|
+
resolve();
|
|
302
294
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
var sql, onConflictPrimary, sentences, newColumns, tableDDL;
|
|
316
|
-
var _this = this;
|
|
317
|
-
return __generator(this, function (_a) {
|
|
318
|
-
switch (_a.label) {
|
|
319
|
-
case 0:
|
|
320
|
-
sql = '';
|
|
321
|
-
sentences = [];
|
|
322
|
-
newColumns = [];
|
|
323
|
-
return [4 /*yield*/, this.tableExists(table.name)];
|
|
324
|
-
case 1:
|
|
325
|
-
tableDDL = _a.sent();
|
|
326
|
-
if (tableDDL) {
|
|
327
|
-
table.columns.forEach(( /**
|
|
328
|
-
* @param {?} col
|
|
329
|
-
* @return {?}
|
|
330
|
-
*/function (col) {
|
|
331
|
-
if (!_this.columnExists(( /** @type {?} */(tableDDL)), col.name)) {
|
|
332
|
-
newColumns.push(_this.addColumn(table.name, col));
|
|
333
|
-
}
|
|
334
|
-
}));
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
table.columns.forEach(( /**
|
|
338
|
-
* @param {?} col
|
|
339
|
-
* @return {?}
|
|
340
|
-
*/function (col) {
|
|
341
|
-
sentences.push(_this.defColumn(col));
|
|
342
|
-
}));
|
|
343
|
-
}
|
|
344
|
-
onConflictPrimary = 'on conflict fail';
|
|
345
|
-
if (Array.isArray(table.primary)) {
|
|
346
|
-
sentences.push(' CONSTRAINT identificador PRIMARY KEY (' + table.primary.join(',') + ') ' + onConflictPrimary);
|
|
347
|
-
}
|
|
348
|
-
if (typeof table.primary === 'string') {
|
|
349
|
-
sentences.push(' CONSTRAINT identificador PRIMARY KEY (' + table.primary + ') ' + onConflictPrimary);
|
|
350
|
-
}
|
|
351
|
-
if (table.uniques) {
|
|
352
|
-
table.uniques.forEach(( /**
|
|
353
|
-
* @param {?} uniq
|
|
354
|
-
* @return {?}
|
|
355
|
-
*/function (uniq) {
|
|
356
|
-
sentences.push(_this.defUnique(uniq));
|
|
357
|
-
}));
|
|
358
|
-
}
|
|
359
|
-
if (table.foreigns) {
|
|
360
|
-
table.foreigns.forEach(( /**
|
|
361
|
-
* @param {?} fore
|
|
362
|
-
* @return {?}
|
|
363
|
-
*/function (fore) {
|
|
364
|
-
sentences.push(_this.defForeign(fore));
|
|
365
|
-
}));
|
|
366
|
-
}
|
|
367
|
-
if (tableDDL && newColumns.length !== 0) {
|
|
368
|
-
return [2 /*return*/, Promise.all(newColumns)
|
|
369
|
-
.then(( /**
|
|
370
|
-
* @return {?}
|
|
371
|
-
*/function () { console.log("Table " + table.name + " altered."); }))
|
|
372
|
-
.catch(( /**
|
|
373
|
-
* @param {?} err
|
|
374
|
-
* @return {?}
|
|
375
|
-
*/function (err) {
|
|
376
|
-
console.error("Table " + table.name + ": " + err.message);
|
|
377
|
-
throw new Error("Table " + table.name + ": " + err.message);
|
|
378
|
-
}))];
|
|
379
|
-
}
|
|
380
|
-
else if (!tableDDL) {
|
|
381
|
-
sql = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + sentences.join(',') + ')';
|
|
382
|
-
return [2 /*return*/, this.query(sql)
|
|
383
|
-
.then(( /**
|
|
384
|
-
* @return {?}
|
|
385
|
-
*/function () { console.log("Table " + table.name + " created."); }))
|
|
386
|
-
.catch(( /**
|
|
387
|
-
* @param {?} err
|
|
388
|
-
* @return {?}
|
|
389
|
-
*/function (err) {
|
|
390
|
-
console.error("Table " + table.name + ": " + err.message);
|
|
391
|
-
throw new Error("Table " + table.name + ": " + err.message);
|
|
392
|
-
}))];
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
return [2 /*return*/, Promise.resolve().then(( /**
|
|
396
|
-
* @return {?}
|
|
397
|
-
*/function () { console.log("Table " + table.name + " initialized."); }))];
|
|
398
|
-
}
|
|
399
|
-
return [2 /*return*/];
|
|
400
|
-
}
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
DbWrapperService.prototype.init = function (dbSchema) {
|
|
298
|
+
var _this = this;
|
|
299
|
+
var window = (new WindowService()).nativeWindow;
|
|
300
|
+
return new Promise(function (resolve, reject) {
|
|
301
|
+
_this.db = window.openDatabase(_this._dbName, '1.0', 'database', -1);
|
|
302
|
+
if (dbSchema) {
|
|
303
|
+
_this.generate(dbSchema).catch(function (err) {
|
|
304
|
+
reject(err);
|
|
305
|
+
}).then(function () {
|
|
306
|
+
resolve();
|
|
401
307
|
});
|
|
402
|
-
});
|
|
403
|
-
};
|
|
404
|
-
/**
|
|
405
|
-
* @param {?} view
|
|
406
|
-
* @return {?}
|
|
407
|
-
*/
|
|
408
|
-
DbWrapperService.prototype.createView = /**
|
|
409
|
-
* @param {?} view
|
|
410
|
-
* @return {?}
|
|
411
|
-
*/
|
|
412
|
-
function (view) {
|
|
413
|
-
/** @type {?} */
|
|
414
|
-
var sql;
|
|
415
|
-
sql = 'CREATE VIEW IF NOT EXISTS ' + view.name
|
|
416
|
-
+ ' AS ' + view.sql;
|
|
417
|
-
return this.query(sql);
|
|
418
|
-
};
|
|
419
|
-
/**
|
|
420
|
-
* @param {?} tableName
|
|
421
|
-
* @return {?}
|
|
422
|
-
*/
|
|
423
|
-
DbWrapperService.prototype.getSchemaTable = /**
|
|
424
|
-
* @param {?} tableName
|
|
425
|
-
* @return {?}
|
|
426
|
-
*/
|
|
427
|
-
function (tableName) {
|
|
428
|
-
/** @type {?} */
|
|
429
|
-
var res;
|
|
430
|
-
this.schema.tables.forEach(( /**
|
|
431
|
-
* @param {?} table
|
|
432
|
-
* @return {?}
|
|
433
|
-
*/function (table) {
|
|
434
|
-
if (table.name === tableName) {
|
|
435
|
-
res = table;
|
|
436
|
-
}
|
|
437
|
-
}));
|
|
438
|
-
return res;
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* @param {?} table
|
|
442
|
-
* @return {?}
|
|
443
|
-
*/
|
|
444
|
-
DbWrapperService.prototype.getUniquesTable = /**
|
|
445
|
-
* @param {?} table
|
|
446
|
-
* @return {?}
|
|
447
|
-
*/
|
|
448
|
-
function (table) {
|
|
449
|
-
/** @type {?} */
|
|
450
|
-
var res;
|
|
451
|
-
table.uniques.forEach(( /**
|
|
452
|
-
* @param {?} uniq
|
|
453
|
-
* @return {?}
|
|
454
|
-
*/function (uniq) {
|
|
455
|
-
res[uniq.name] = uniq;
|
|
456
|
-
}));
|
|
457
|
-
return res;
|
|
458
|
-
};
|
|
459
|
-
/**
|
|
460
|
-
* @param {?} query
|
|
461
|
-
* @param {?=} bindings
|
|
462
|
-
* @return {?}
|
|
463
|
-
*/
|
|
464
|
-
DbWrapperService.prototype.query = /**
|
|
465
|
-
* @param {?} query
|
|
466
|
-
* @param {?=} bindings
|
|
467
|
-
* @return {?}
|
|
468
|
-
*/
|
|
469
|
-
function (query, bindings) {
|
|
470
|
-
var _this = this;
|
|
471
|
-
if (bindings === void 0) {
|
|
472
|
-
bindings = [];
|
|
473
|
-
}
|
|
474
|
-
return new Promise(( /**
|
|
475
|
-
* @param {?} resolve
|
|
476
|
-
* @param {?} reject
|
|
477
|
-
* @return {?}
|
|
478
|
-
*/function (resolve, reject) {
|
|
479
|
-
if (query.indexOf('select') === 0) {
|
|
480
|
-
_this.db.readTransaction(( /**
|
|
481
|
-
* @param {?} transaction
|
|
482
|
-
* @return {?}
|
|
483
|
-
*/function (transaction) {
|
|
484
|
-
transaction.executeSql(query, bindings, ( /**
|
|
485
|
-
* @param {?} transaction
|
|
486
|
-
* @param {?} result
|
|
487
|
-
* @return {?}
|
|
488
|
-
*/function (transaction, result) {
|
|
489
|
-
resolve(result);
|
|
490
|
-
}), ( /**
|
|
491
|
-
* @param {?} transaction
|
|
492
|
-
* @param {?} error
|
|
493
|
-
* @return {?}
|
|
494
|
-
*/function (transaction, error) {
|
|
495
|
-
reject(error);
|
|
496
|
-
}));
|
|
497
|
-
}), ( /**
|
|
498
|
-
* @param {?} err
|
|
499
|
-
* @return {?}
|
|
500
|
-
*/function (err) { return reject(err); }));
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
_this.db.transaction(( /**
|
|
504
|
-
* @param {?} transaction
|
|
505
|
-
* @return {?}
|
|
506
|
-
*/function (transaction) {
|
|
507
|
-
transaction.executeSql(query, bindings, ( /**
|
|
508
|
-
* @param {?} transaction
|
|
509
|
-
* @param {?} result
|
|
510
|
-
* @return {?}
|
|
511
|
-
*/function (transaction, result) {
|
|
512
|
-
resolve(result);
|
|
513
|
-
}), ( /**
|
|
514
|
-
* @param {?} transaction
|
|
515
|
-
* @param {?} error
|
|
516
|
-
* @return {?}
|
|
517
|
-
*/function (transaction, error) {
|
|
518
|
-
reject(error);
|
|
519
|
-
}));
|
|
520
|
-
}), ( /**
|
|
521
|
-
* @param {?} err
|
|
522
|
-
* @return {?}
|
|
523
|
-
*/function (err) { return reject(err); }));
|
|
524
|
-
}
|
|
525
|
-
}));
|
|
526
|
-
};
|
|
527
|
-
/**
|
|
528
|
-
* @param {?} query
|
|
529
|
-
* @param {?=} bindings
|
|
530
|
-
* @return {?}
|
|
531
|
-
*/
|
|
532
|
-
DbWrapperService.prototype.Count = /**
|
|
533
|
-
* @param {?} query
|
|
534
|
-
* @param {?=} bindings
|
|
535
|
-
* @return {?}
|
|
536
|
-
*/
|
|
537
|
-
function (query, bindings) {
|
|
538
|
-
var _this = this;
|
|
539
|
-
if (bindings === void 0) {
|
|
540
|
-
bindings = [];
|
|
541
308
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
* @return {?}
|
|
545
|
-
*/function (rows) {
|
|
546
|
-
return _this.rowsCount(rows);
|
|
547
|
-
}));
|
|
548
|
-
};
|
|
549
|
-
/**
|
|
550
|
-
* @param {?} table
|
|
551
|
-
* @param {?} bindings
|
|
552
|
-
* @return {?}
|
|
553
|
-
*/
|
|
554
|
-
DbWrapperService.prototype.insert = /**
|
|
555
|
-
* @param {?} table
|
|
556
|
-
* @param {?} bindings
|
|
557
|
-
* @return {?}
|
|
558
|
-
*/
|
|
559
|
-
function (table, bindings) {
|
|
560
|
-
var _this = this;
|
|
561
|
-
/** @type {?} */
|
|
562
|
-
var sql = '';
|
|
563
|
-
/** @type {?} */
|
|
564
|
-
var sqlBinds = [];
|
|
565
|
-
/** @type {?} */
|
|
566
|
-
var sqlKeys = [];
|
|
567
|
-
/** @type {?} */
|
|
568
|
-
var sqlValues = [];
|
|
569
|
-
sql = sql + 'insert into ' + table + ' ';
|
|
570
|
-
for (var index in bindings) {
|
|
571
|
-
if (bindings.hasOwnProperty(index)) {
|
|
572
|
-
sqlKeys.push(index);
|
|
573
|
-
sqlValues.push(bindings[index]);
|
|
574
|
-
sqlBinds.push('?');
|
|
575
|
-
}
|
|
309
|
+
else {
|
|
310
|
+
resolve();
|
|
576
311
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}));
|
|
602
|
-
};
|
|
603
|
-
/**
|
|
604
|
-
* @param {?} table
|
|
605
|
-
* @param {?} bindings
|
|
606
|
-
* @param {?} where
|
|
607
|
-
* @return {?}
|
|
608
|
-
*/
|
|
609
|
-
DbWrapperService.prototype.update = /**
|
|
610
|
-
* @param {?} table
|
|
611
|
-
* @param {?} bindings
|
|
612
|
-
* @param {?} where
|
|
613
|
-
* @return {?}
|
|
614
|
-
*/
|
|
615
|
-
function (table, bindings, where) {
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
DbWrapperService.prototype.generate = function (schema) {
|
|
315
|
+
var _this = this;
|
|
316
|
+
var sentences = [];
|
|
317
|
+
this.schema = schema;
|
|
318
|
+
if (schema.tables) {
|
|
319
|
+
schema.tables.forEach(function (table) {
|
|
320
|
+
sentences.push(_this.createTable(table));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (schema.views) {
|
|
324
|
+
schema.views.forEach(function (view) {
|
|
325
|
+
sentences.push(_this.createView(view));
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (sentences.length === 0) {
|
|
329
|
+
throw new Error('Esquema de la base de datos vacia.');
|
|
330
|
+
}
|
|
331
|
+
return Promise.all(sentences);
|
|
332
|
+
};
|
|
333
|
+
DbWrapperService.prototype.createTable = function (table) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
335
|
+
var sql, onConflictPrimary, sentences, newColumns, tableDDL;
|
|
616
336
|
var _this = this;
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
337
|
+
return __generator(this, function (_a) {
|
|
338
|
+
switch (_a.label) {
|
|
339
|
+
case 0:
|
|
340
|
+
sql = '';
|
|
341
|
+
sentences = [], newColumns = [];
|
|
342
|
+
return [4 /*yield*/, this._tableExists(table.name)];
|
|
343
|
+
case 1:
|
|
344
|
+
tableDDL = _a.sent();
|
|
345
|
+
if (tableDDL) {
|
|
346
|
+
table.columns.forEach(function (col) {
|
|
347
|
+
if (!_this._columnExists(tableDDL, col.name)) {
|
|
348
|
+
newColumns.push(_this.addColumn(table.name, col));
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
table.columns.forEach(function (col) {
|
|
354
|
+
sentences.push(_this.defColumn(col));
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
onConflictPrimary = 'on conflict fail';
|
|
358
|
+
if (Array.isArray(table.primary)) {
|
|
359
|
+
sentences.push(' CONSTRAINT identificador PRIMARY KEY (' + table.primary.join(',') + ') ' + onConflictPrimary);
|
|
360
|
+
}
|
|
361
|
+
if (typeof table.primary === 'string') {
|
|
362
|
+
sentences.push(' CONSTRAINT identificador PRIMARY KEY (' + table.primary + ') ' + onConflictPrimary);
|
|
363
|
+
}
|
|
364
|
+
if (table.uniques) {
|
|
365
|
+
table.uniques.forEach(function (uniq) {
|
|
366
|
+
sentences.push(_this.defUnique(uniq));
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
if (table.foreigns) {
|
|
370
|
+
table.foreigns.forEach(function (fore) {
|
|
371
|
+
sentences.push(_this.defForeign(fore));
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
if (tableDDL && newColumns.length !== 0) {
|
|
375
|
+
return [2 /*return*/, Promise.all(newColumns)
|
|
376
|
+
.then(function () { console.log("Table " + table.name + " altered."); })
|
|
377
|
+
.catch(function (err) {
|
|
378
|
+
console.error("Table " + table.name + ": " + err.message);
|
|
379
|
+
throw new Error("Table " + table.name + ": " + err.message);
|
|
380
|
+
})];
|
|
634
381
|
}
|
|
635
|
-
else if (
|
|
636
|
-
|
|
382
|
+
else if (!tableDDL) {
|
|
383
|
+
sql = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + sentences.join(',') + ')';
|
|
384
|
+
return [2 /*return*/, this.query(sql)
|
|
385
|
+
.then(function () { console.log("Table " + table.name + " created."); })
|
|
386
|
+
.catch(function (err) {
|
|
387
|
+
console.error("Table " + table.name + ": " + err.message);
|
|
388
|
+
throw new Error("Table " + table.name + ": " + err.message);
|
|
389
|
+
})];
|
|
637
390
|
}
|
|
638
391
|
else {
|
|
639
|
-
|
|
392
|
+
return [2 /*return*/, Promise.resolve().then(function () { console.log("Table " + table.name + " initialized."); })];
|
|
640
393
|
}
|
|
641
|
-
|
|
642
|
-
else {
|
|
643
|
-
sqlBinds.push(index + ' = ?');
|
|
644
|
-
sqlValues.push(bindings[index]);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
for (var index in where) {
|
|
649
|
-
if (where.hasOwnProperty(index)) {
|
|
650
|
-
if (typeof where[index] === 'object' && where[index] !== null) {
|
|
651
|
-
sqlKeys.push(index + ' ' + where[index].operator + ' ?');
|
|
652
|
-
sqlValues.push(where[index].value);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
sqlKeys.push(index + ' = ?');
|
|
656
|
-
sqlValues.push(where[index]);
|
|
657
|
-
}
|
|
394
|
+
return [2 /*return*/];
|
|
658
395
|
}
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
DbWrapperService.prototype.createView = function (view) {
|
|
400
|
+
var sql;
|
|
401
|
+
sql = 'CREATE VIEW IF NOT EXISTS ' + view.name
|
|
402
|
+
+ ' AS ' + view.sql;
|
|
403
|
+
return this.query(sql);
|
|
404
|
+
};
|
|
405
|
+
DbWrapperService.prototype.getSchemaTable = function (tableName) {
|
|
406
|
+
var res;
|
|
407
|
+
this.schema.tables.forEach(function (table) {
|
|
408
|
+
if (table.name === tableName) {
|
|
409
|
+
res = table;
|
|
659
410
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
411
|
+
});
|
|
412
|
+
return res;
|
|
413
|
+
};
|
|
414
|
+
DbWrapperService.prototype.getUniquesTable = function (table) {
|
|
415
|
+
var res;
|
|
416
|
+
table.uniques.forEach(function (uniq) {
|
|
417
|
+
res[uniq.name] = uniq;
|
|
418
|
+
});
|
|
419
|
+
return res;
|
|
420
|
+
};
|
|
421
|
+
DbWrapperService.prototype.query = function (query, bindings) {
|
|
422
|
+
var _this = this;
|
|
423
|
+
if (bindings === void 0) { bindings = []; }
|
|
424
|
+
return new Promise(function (resolve, reject) {
|
|
425
|
+
if (query.indexOf('select') === 0) {
|
|
426
|
+
_this.db.readTransaction(function (transaction) {
|
|
427
|
+
transaction.executeSql(query, bindings, function (transaction, result) {
|
|
675
428
|
resolve(result);
|
|
676
|
-
}
|
|
677
|
-
* @param {?} transaction
|
|
678
|
-
* @param {?} error
|
|
679
|
-
* @return {?}
|
|
680
|
-
*/function (transaction, error) {
|
|
429
|
+
}, function (transaction, error) {
|
|
681
430
|
reject(error);
|
|
682
|
-
})
|
|
683
|
-
}));
|
|
684
|
-
}));
|
|
685
|
-
};
|
|
686
|
-
/**
|
|
687
|
-
* @param {?} tables
|
|
688
|
-
* @return {?}
|
|
689
|
-
*/
|
|
690
|
-
DbWrapperService.prototype.dropTable = /**
|
|
691
|
-
* @param {?} tables
|
|
692
|
-
* @return {?}
|
|
693
|
-
*/
|
|
694
|
-
function (tables) {
|
|
695
|
-
var _this = this;
|
|
696
|
-
/** @type {?} */
|
|
697
|
-
var cont = 1;
|
|
698
|
-
cont = tables.length;
|
|
699
|
-
return new Promise(( /**
|
|
700
|
-
* @param {?} resolve
|
|
701
|
-
* @param {?} reject
|
|
702
|
-
* @return {?}
|
|
703
|
-
*/function (resolve, reject) {
|
|
704
|
-
tables.some(( /**
|
|
705
|
-
* @param {?} table
|
|
706
|
-
* @return {?}
|
|
707
|
-
*/function (table) {
|
|
708
|
-
if (cont !== 0) {
|
|
709
|
-
_this.query('DROP TABLE ' + table)
|
|
710
|
-
.then(( /**
|
|
711
|
-
* @return {?}
|
|
712
|
-
*/function () {
|
|
713
|
-
if (cont === 1) {
|
|
714
|
-
resolve();
|
|
715
|
-
}
|
|
716
|
-
else {
|
|
717
|
-
cont--;
|
|
718
|
-
}
|
|
719
|
-
}), ( /**
|
|
720
|
-
* @param {?} err
|
|
721
|
-
* @return {?}
|
|
722
|
-
*/function (err) {
|
|
723
|
-
cont = 0;
|
|
724
|
-
reject(err);
|
|
725
|
-
return true;
|
|
726
|
-
}));
|
|
727
|
-
return false;
|
|
728
|
-
}
|
|
729
|
-
}));
|
|
730
|
-
}));
|
|
731
|
-
};
|
|
732
|
-
/**
|
|
733
|
-
* @param {?} result
|
|
734
|
-
* @return {?}
|
|
735
|
-
*/
|
|
736
|
-
DbWrapperService.prototype.fetchAll = /**
|
|
737
|
-
* @param {?} result
|
|
738
|
-
* @return {?}
|
|
739
|
-
*/
|
|
740
|
-
function (result) {
|
|
741
|
-
/** @type {?} */
|
|
742
|
-
var output = [];
|
|
743
|
-
for (var i = 0; i < result.rows.length; i++) {
|
|
744
|
-
output.push(result.rows.item(i));
|
|
745
|
-
}
|
|
746
|
-
return output;
|
|
747
|
-
};
|
|
748
|
-
/**
|
|
749
|
-
* @param {?} result
|
|
750
|
-
* @return {?}
|
|
751
|
-
*/
|
|
752
|
-
DbWrapperService.prototype.fetch = /**
|
|
753
|
-
* @param {?} result
|
|
754
|
-
* @return {?}
|
|
755
|
-
*/
|
|
756
|
-
function (result) {
|
|
757
|
-
/** @type {?} */
|
|
758
|
-
var objeto = undefined;
|
|
759
|
-
/** @type {?} */
|
|
760
|
-
var newObj = undefined;
|
|
761
|
-
if (result.rows.length !== 0) {
|
|
762
|
-
objeto = result.rows.item(0);
|
|
763
|
-
newObj = {};
|
|
764
|
-
/** @type {?} */
|
|
765
|
-
var keys = Object.keys(objeto);
|
|
766
|
-
for (var key in keys) {
|
|
767
|
-
newObj[keys[key]] = objeto[keys[key]];
|
|
768
|
-
}
|
|
431
|
+
});
|
|
432
|
+
}, function (err) { return reject(err); });
|
|
769
433
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
* @return {?}
|
|
779
|
-
*/
|
|
780
|
-
function (result) {
|
|
781
|
-
return result.rows.length;
|
|
782
|
-
};
|
|
783
|
-
/* Private */
|
|
784
|
-
/* Private */
|
|
785
|
-
/**
|
|
786
|
-
* @private
|
|
787
|
-
* @param {?} col
|
|
788
|
-
* @return {?}
|
|
789
|
-
*/
|
|
790
|
-
DbWrapperService.prototype.defColumn = /* Private */
|
|
791
|
-
/**
|
|
792
|
-
* @private
|
|
793
|
-
* @param {?} col
|
|
794
|
-
* @return {?}
|
|
795
|
-
*/
|
|
796
|
-
function (col) {
|
|
797
|
-
/** @type {?} */
|
|
798
|
-
var colSql;
|
|
799
|
-
colSql = col.name + ' ' + col.type;
|
|
800
|
-
if (!col.isNullable) {
|
|
801
|
-
colSql += ' NOT NULL ';
|
|
434
|
+
else {
|
|
435
|
+
_this.db.transaction(function (transaction) {
|
|
436
|
+
transaction.executeSql(query, bindings, function (transaction, result) {
|
|
437
|
+
resolve(result);
|
|
438
|
+
}, function (transaction, error) {
|
|
439
|
+
reject(error);
|
|
440
|
+
});
|
|
441
|
+
}, function (err) { return reject(err); });
|
|
802
442
|
}
|
|
803
|
-
|
|
804
|
-
|
|
443
|
+
});
|
|
444
|
+
};
|
|
445
|
+
DbWrapperService.prototype.Count = function (query, bindings) {
|
|
446
|
+
var _this = this;
|
|
447
|
+
if (bindings === void 0) { bindings = []; }
|
|
448
|
+
return this.query(query, bindings).then(function (rows) {
|
|
449
|
+
return _this.rowsCount(rows);
|
|
450
|
+
});
|
|
451
|
+
};
|
|
452
|
+
DbWrapperService.prototype.insert = function (table, bindings) {
|
|
453
|
+
var _this = this;
|
|
454
|
+
var sql = '', sqlBinds = [], sqlKeys = [], sqlValues = [];
|
|
455
|
+
sql = sql + 'insert into ' + table + ' ';
|
|
456
|
+
for (var index in bindings) {
|
|
457
|
+
if (bindings.hasOwnProperty(index)) {
|
|
458
|
+
sqlKeys.push(index);
|
|
459
|
+
sqlValues.push(bindings[index]);
|
|
460
|
+
sqlBinds.push('?');
|
|
805
461
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
462
|
+
}
|
|
463
|
+
sql = sql + '(' + sqlKeys.join(',') + ') values (' + sqlBinds.join(',') + ')';
|
|
464
|
+
return new Promise(function (resolve, reject) {
|
|
465
|
+
_this.db.transaction(function (transaction) {
|
|
466
|
+
transaction.executeSql(sql, sqlValues, function (transaction, result) {
|
|
467
|
+
resolve(result);
|
|
468
|
+
}, function (transaction, error) {
|
|
469
|
+
reject(error);
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
DbWrapperService.prototype.update = function (table, bindings, where) {
|
|
475
|
+
var _this = this;
|
|
476
|
+
var sql = '', sqlBinds = [], sqlKeys = [], sqlValues = [];
|
|
477
|
+
sql = sql + 'update ' + table + ' set ';
|
|
478
|
+
for (var index in bindings) {
|
|
479
|
+
if (bindings.hasOwnProperty(index)) {
|
|
480
|
+
var newObj = bindings[index];
|
|
481
|
+
if (typeof newObj === 'object' && newObj !== null) {
|
|
482
|
+
sqlValues.push(newObj.value);
|
|
483
|
+
if (newObj.ifnull) {
|
|
484
|
+
sqlBinds.push(index + ' = ifnull( ' + index + ',0) + ?');
|
|
485
|
+
}
|
|
486
|
+
else if (newObj.operator) {
|
|
487
|
+
sqlBinds.push(index + ' = ' + index + newObj.operator + ' ?');
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
sqlBinds.push(index + ' = ?');
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
sqlBinds.push(index + ' = ?');
|
|
495
|
+
sqlValues.push(bindings[index]);
|
|
810
496
|
}
|
|
811
|
-
colSql += "length(" + col.name + ") <= " + col.length + " )";
|
|
812
|
-
}
|
|
813
|
-
return colSql;
|
|
814
|
-
};
|
|
815
|
-
/**
|
|
816
|
-
* @private
|
|
817
|
-
* @param {?} unique
|
|
818
|
-
* @return {?}
|
|
819
|
-
*/
|
|
820
|
-
DbWrapperService.prototype.defUnique = /**
|
|
821
|
-
* @private
|
|
822
|
-
* @param {?} unique
|
|
823
|
-
* @return {?}
|
|
824
|
-
*/
|
|
825
|
-
function (unique) {
|
|
826
|
-
/** @type {?} */
|
|
827
|
-
var uniqSql;
|
|
828
|
-
// depende del entorno, producción o desarrollo
|
|
829
|
-
/** @type {?} */
|
|
830
|
-
var onConflictUnique = 'on conflict fail';
|
|
831
|
-
if (Array.isArray(unique.fields)) {
|
|
832
|
-
uniqSql = " CONSTRAINT " + unique.name + " UNIQUE ( " + unique.fields.join(',') + " ) " + onConflictUnique + " ";
|
|
833
|
-
}
|
|
834
|
-
if (typeof unique.fields === 'string') {
|
|
835
|
-
uniqSql = " CONSTRAINT " + unique.name + " UNIQUE ( " + unique.fields + " ) " + onConflictUnique + " ";
|
|
836
|
-
}
|
|
837
|
-
return uniqSql;
|
|
838
|
-
};
|
|
839
|
-
/**
|
|
840
|
-
* @private
|
|
841
|
-
* @param {?} fore
|
|
842
|
-
* @return {?}
|
|
843
|
-
*/
|
|
844
|
-
DbWrapperService.prototype.defForeign = /**
|
|
845
|
-
* @private
|
|
846
|
-
* @param {?} fore
|
|
847
|
-
* @return {?}
|
|
848
|
-
*/
|
|
849
|
-
function (fore) {
|
|
850
|
-
/** @type {?} */
|
|
851
|
-
var foreSql;
|
|
852
|
-
if (Array.isArray(fore.foreignKey)) {
|
|
853
|
-
foreSql = " FOREIGN KEY ( " + fore.foreignKey.join(',') + " ) ";
|
|
854
|
-
}
|
|
855
|
-
if (typeof fore.foreignKey === 'string') {
|
|
856
|
-
foreSql = " FOREIGN KEY ( " + fore.foreignKey + " ) ";
|
|
857
|
-
}
|
|
858
|
-
if (Array.isArray(fore.primaryKey)) {
|
|
859
|
-
foreSql = " REFERENCES " + fore.referenceTable + " ( " + fore.primaryKey.join(',') + " ) ";
|
|
860
|
-
}
|
|
861
|
-
if (typeof fore.primaryKey === 'string') {
|
|
862
|
-
foreSql = " REFERENCES " + fore.referenceTable + " ( " + fore.primaryKey + " ) ";
|
|
863
497
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
*/
|
|
871
|
-
DbWrapperService.prototype.tableExists = /**
|
|
872
|
-
* @private
|
|
873
|
-
* @param {?} table
|
|
874
|
-
* @return {?}
|
|
875
|
-
*/
|
|
876
|
-
function (table) {
|
|
877
|
-
var _this = this;
|
|
878
|
-
return this.query('select sql from sqlite_master ' +
|
|
879
|
-
'where type=\'table\' and name=\'' + table + '\'')
|
|
880
|
-
.then(( /**
|
|
881
|
-
* @param {?} result
|
|
882
|
-
* @return {?}
|
|
883
|
-
*/function (result) {
|
|
884
|
-
if (_this.rowsCount(result) === 1) {
|
|
885
|
-
return ( /** @type {?} */((( /** @type {?} */(_this.fetch(result)))).sql));
|
|
498
|
+
}
|
|
499
|
+
for (var index in where) {
|
|
500
|
+
if (where.hasOwnProperty(index)) {
|
|
501
|
+
if (typeof where[index] === 'object' && where[index] !== null) {
|
|
502
|
+
sqlKeys.push(index + ' ' + where[index].operator + ' ?');
|
|
503
|
+
sqlValues.push(where[index].value);
|
|
886
504
|
}
|
|
887
505
|
else {
|
|
506
|
+
sqlKeys.push(index + ' = ?');
|
|
507
|
+
sqlValues.push(where[index]);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
sql = sql + sqlBinds.join(',') + ' where ' + sqlKeys.join(' and ');
|
|
512
|
+
return new Promise(function (resolve, reject) {
|
|
513
|
+
_this.db.transaction(function (transaction) {
|
|
514
|
+
transaction.executeSql(sql, sqlValues, function (transaction, result) {
|
|
515
|
+
resolve(result);
|
|
516
|
+
}, function (transaction, error) {
|
|
517
|
+
reject(error);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
DbWrapperService.prototype.dropTable = function (tables) {
|
|
523
|
+
var _this = this;
|
|
524
|
+
var cont = 1;
|
|
525
|
+
cont = tables.length;
|
|
526
|
+
return new Promise(function (resolve, reject) {
|
|
527
|
+
tables.some(function (table) {
|
|
528
|
+
if (cont !== 0) {
|
|
529
|
+
_this.query('DROP TABLE ' + table)
|
|
530
|
+
.then(function () {
|
|
531
|
+
if (cont === 1) {
|
|
532
|
+
resolve();
|
|
533
|
+
}
|
|
534
|
+
else {
|
|
535
|
+
cont--;
|
|
536
|
+
}
|
|
537
|
+
}, function (err) {
|
|
538
|
+
cont = 0;
|
|
539
|
+
reject(err);
|
|
540
|
+
return true;
|
|
541
|
+
});
|
|
888
542
|
return false;
|
|
889
543
|
}
|
|
890
|
-
})
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
DbWrapperService.prototype.fetchAll = function (result) {
|
|
548
|
+
var output = [];
|
|
549
|
+
for (var i = 0; i < result.rows.length; i++) {
|
|
550
|
+
output.push(result.rows.item(i));
|
|
551
|
+
}
|
|
552
|
+
return output;
|
|
553
|
+
};
|
|
554
|
+
DbWrapperService.prototype.fetch = function (result) {
|
|
555
|
+
var objeto = undefined, newObj = undefined;
|
|
556
|
+
if (result.rows.length !== 0) {
|
|
557
|
+
objeto = result.rows.item(0);
|
|
558
|
+
newObj = {};
|
|
559
|
+
var keys = Object.keys(objeto);
|
|
560
|
+
for (var key in keys) {
|
|
561
|
+
newObj[keys[key]] = objeto[keys[key]];
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return newObj;
|
|
565
|
+
};
|
|
566
|
+
DbWrapperService.prototype.rowsCount = function (result) {
|
|
567
|
+
return result.rows.length;
|
|
568
|
+
};
|
|
569
|
+
DbWrapperService.prototype.tableExists = function (table) {
|
|
570
|
+
var _this = this;
|
|
571
|
+
return this.query('select sql from sqlite_master ' +
|
|
572
|
+
'where type=\'table\' and name=\'' + table + '\'')
|
|
573
|
+
.then(function (result) { return (_this.rowsCount(result) === 1); });
|
|
574
|
+
};
|
|
575
|
+
DbWrapperService.prototype.columnExists = function (table, column) {
|
|
576
|
+
var _this = this;
|
|
577
|
+
return this._tableExists(table)
|
|
578
|
+
.then(function (tableDDL) {
|
|
579
|
+
if (tableDDL) {
|
|
580
|
+
return _this._columnExists(tableDDL, column);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
906
583
|
return false;
|
|
907
584
|
}
|
|
585
|
+
});
|
|
586
|
+
};
|
|
587
|
+
/* Private */
|
|
588
|
+
DbWrapperService.prototype.defColumn = function (col) {
|
|
589
|
+
var colSql;
|
|
590
|
+
colSql = col.name + ' ' + col.type;
|
|
591
|
+
if (!col.isNullable) {
|
|
592
|
+
colSql += ' NOT NULL ';
|
|
593
|
+
}
|
|
594
|
+
if (col.default) {
|
|
595
|
+
colSql += ' DEFAULT ' + col.default + ' ';
|
|
596
|
+
}
|
|
597
|
+
if (col.type === 'text' && col.length) {
|
|
598
|
+
colSql += " CONSTRAINT " + col.name + "_length CHECK ( ";
|
|
599
|
+
if (col.isNullable) {
|
|
600
|
+
colSql += col.name + " is null OR ";
|
|
601
|
+
}
|
|
602
|
+
colSql += "length(" + col.name + ") <= " + col.length + " )";
|
|
603
|
+
}
|
|
604
|
+
return colSql;
|
|
605
|
+
};
|
|
606
|
+
DbWrapperService.prototype.defUnique = function (unique) {
|
|
607
|
+
var uniqSql;
|
|
608
|
+
// depende del entorno, producción o desarrollo
|
|
609
|
+
var onConflictUnique = 'on conflict replace';
|
|
610
|
+
if (Array.isArray(unique.fields)) {
|
|
611
|
+
uniqSql = " CONSTRAINT " + unique.name + " UNIQUE ( " + unique.fields.join(',') + " ) " + onConflictUnique + " ";
|
|
612
|
+
}
|
|
613
|
+
if (typeof unique.fields === 'string') {
|
|
614
|
+
uniqSql = " CONSTRAINT " + unique.name + " UNIQUE ( " + unique.fields + " ) " + onConflictUnique + " ";
|
|
615
|
+
}
|
|
616
|
+
return uniqSql;
|
|
617
|
+
};
|
|
618
|
+
DbWrapperService.prototype.defForeign = function (fore) {
|
|
619
|
+
var foreSql;
|
|
620
|
+
if (Array.isArray(fore.foreignKey)) {
|
|
621
|
+
foreSql = " FOREIGN KEY ( " + fore.foreignKey.join(',') + " ) ";
|
|
622
|
+
}
|
|
623
|
+
if (typeof fore.foreignKey === 'string') {
|
|
624
|
+
foreSql = " FOREIGN KEY ( " + fore.foreignKey + " ) ";
|
|
625
|
+
}
|
|
626
|
+
if (Array.isArray(fore.primaryKey)) {
|
|
627
|
+
foreSql = " REFERENCES " + fore.referenceTable + " ( " + fore.primaryKey.join(',') + " ) ";
|
|
628
|
+
}
|
|
629
|
+
if (typeof fore.primaryKey === 'string') {
|
|
630
|
+
foreSql = " REFERENCES " + fore.referenceTable + " ( " + fore.primaryKey + " ) ";
|
|
631
|
+
}
|
|
632
|
+
return foreSql;
|
|
633
|
+
};
|
|
634
|
+
DbWrapperService.prototype._tableExists = function (table) {
|
|
635
|
+
var _this = this;
|
|
636
|
+
return this.query('select sql from sqlite_master ' +
|
|
637
|
+
'where type=\'table\' and name=\'' + table + '\'')
|
|
638
|
+
.then(function (result) {
|
|
639
|
+
if (_this.rowsCount(result) === 1) {
|
|
640
|
+
return _this.fetch(result).sql;
|
|
641
|
+
}
|
|
908
642
|
else {
|
|
909
|
-
return
|
|
643
|
+
return false;
|
|
910
644
|
}
|
|
911
|
-
};
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
var colSql = this.defColumn(col);
|
|
927
|
-
/** @type {?} */
|
|
928
|
-
var query = 'alter TABLE ' + table + ' add COLUMN ' + colSql;
|
|
929
|
-
return this.query(query);
|
|
930
|
-
};
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
DbWrapperService.prototype._columnExists = function (tableDDL, column) {
|
|
648
|
+
if (tableDDL.indexOf(column) === -1) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
DbWrapperService.prototype.addColumn = function (table, col) {
|
|
656
|
+
var colSql = this.defColumn(col);
|
|
657
|
+
var query = 'alter TABLE ' + table + ' add COLUMN ' + colSql;
|
|
658
|
+
return this.query(query);
|
|
659
|
+
};
|
|
931
660
|
return DbWrapperService;
|
|
932
661
|
}());
|
|
933
|
-
/** @type {?} */
|
|
934
662
|
var DB_CONFIG = new core.InjectionToken('dbWrapperConfig');
|
|
935
|
-
/** @type {?} */
|
|
936
663
|
var DB_SCHEMA = new core.InjectionToken('dbWrapperSchema');
|
|
937
|
-
/**
|
|
938
|
-
* @return {?}
|
|
939
|
-
*/
|
|
940
664
|
function getDefaultDbConfig() {
|
|
941
665
|
return {
|
|
942
666
|
dbName: 'db.sqlite',
|
|
@@ -944,120 +668,85 @@
|
|
|
944
668
|
iosDatabaseLocation: 'Library'
|
|
945
669
|
};
|
|
946
670
|
}
|
|
947
|
-
/**
|
|
948
|
-
* @param {?} dbConfig
|
|
949
|
-
* @param {?=} dbSchema
|
|
950
|
-
* @return {?}
|
|
951
|
-
*/
|
|
952
671
|
function provideDbWrapper(dbConfig, dbSchema) {
|
|
953
|
-
/** @type {?} */
|
|
954
672
|
var config = !!dbConfig ? dbConfig : getDefaultDbConfig();
|
|
955
673
|
return new DbWrapperService(config, dbSchema);
|
|
956
674
|
}
|
|
957
675
|
|
|
958
|
-
/**
|
|
959
|
-
* @fileoverview added by tsickle
|
|
960
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
961
|
-
*/
|
|
962
676
|
var DbWrapperModule = /** @class */ (function () {
|
|
963
677
|
function DbWrapperModule() {
|
|
964
678
|
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
*/
|
|
975
|
-
function (dbConfig, schema) {
|
|
976
|
-
return {
|
|
977
|
-
ngModule: DbWrapperModule,
|
|
978
|
-
providers: [
|
|
979
|
-
{ provide: DB_CONFIG, useValue: dbConfig },
|
|
980
|
-
{ provide: DB_SCHEMA, useValue: schema },
|
|
981
|
-
{ provide: DbWrapperService, useFactory: provideDbWrapper, deps: [DB_CONFIG, DB_SCHEMA] }
|
|
982
|
-
]
|
|
983
|
-
};
|
|
679
|
+
DbWrapperModule_1 = DbWrapperModule;
|
|
680
|
+
DbWrapperModule.forRoot = function (dbConfig, schema) {
|
|
681
|
+
return {
|
|
682
|
+
ngModule: DbWrapperModule_1,
|
|
683
|
+
providers: [
|
|
684
|
+
{ provide: DB_CONFIG, useValue: dbConfig },
|
|
685
|
+
{ provide: DB_SCHEMA, useValue: schema },
|
|
686
|
+
{ provide: DbWrapperService, useFactory: provideDbWrapper, deps: [DB_CONFIG, DB_SCHEMA] }
|
|
687
|
+
]
|
|
984
688
|
};
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
689
|
+
};
|
|
690
|
+
var DbWrapperModule_1;
|
|
691
|
+
DbWrapperModule = DbWrapperModule_1 = __decorate([
|
|
692
|
+
core.NgModule()
|
|
693
|
+
], DbWrapperModule);
|
|
988
694
|
return DbWrapperModule;
|
|
989
695
|
}());
|
|
990
696
|
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
Boolean: '0',
|
|
1036
|
-
DateTime: '(datetime(\'now\', \'localtime\'))',
|
|
1037
|
-
Date: '(date(\'now\', \'localtime\'))',
|
|
1038
|
-
};
|
|
1039
|
-
|
|
1040
|
-
/**
|
|
1041
|
-
* @fileoverview added by tsickle
|
|
1042
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1043
|
-
*/
|
|
1044
|
-
|
|
1045
|
-
/**
|
|
1046
|
-
* @fileoverview added by tsickle
|
|
1047
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1048
|
-
*/
|
|
697
|
+
|
|
698
|
+
(function (DataType) {
|
|
699
|
+
DataType["Integer"] = "integer";
|
|
700
|
+
DataType["Int"] = "integer";
|
|
701
|
+
DataType["TinyInt"] = "integer";
|
|
702
|
+
DataType["SmallInt"] = "integer";
|
|
703
|
+
DataType["BigInt"] = "integer";
|
|
704
|
+
DataType["Text"] = "text";
|
|
705
|
+
DataType["Char"] = "text";
|
|
706
|
+
DataType["NChar"] = "text";
|
|
707
|
+
DataType["VarChar"] = "text";
|
|
708
|
+
DataType["NVarChar"] = "text";
|
|
709
|
+
DataType["CLOB"] = "text";
|
|
710
|
+
DataType["BLOB"] = "blob";
|
|
711
|
+
DataType["Real"] = "real";
|
|
712
|
+
DataType["Double"] = "real";
|
|
713
|
+
DataType["Decimal"] = "real";
|
|
714
|
+
DataType["Float"] = "real";
|
|
715
|
+
DataType["Boolean"] = "integer";
|
|
716
|
+
DataType["DateTime"] = "text";
|
|
717
|
+
DataType["Date"] = "text";
|
|
718
|
+
})(exports.DataType || (exports.DataType = {}));
|
|
719
|
+
|
|
720
|
+
(function (DefaultType) {
|
|
721
|
+
DefaultType["Integer"] = "0";
|
|
722
|
+
DefaultType["Int"] = "0";
|
|
723
|
+
DefaultType["TinyInt"] = "0";
|
|
724
|
+
DefaultType["SmallInt"] = "0";
|
|
725
|
+
DefaultType["BigInt"] = "0";
|
|
726
|
+
DefaultType["Text"] = "''";
|
|
727
|
+
DefaultType["Char"] = "''";
|
|
728
|
+
DefaultType["NChar"] = "''";
|
|
729
|
+
DefaultType["VarChar"] = "''";
|
|
730
|
+
DefaultType["NVarChar"] = "''";
|
|
731
|
+
DefaultType["CLOB"] = "''";
|
|
732
|
+
DefaultType["BLOB"] = "0";
|
|
733
|
+
DefaultType["Real"] = "0.0";
|
|
734
|
+
DefaultType["Double"] = "0.0";
|
|
735
|
+
DefaultType["Decimal"] = "0.0";
|
|
736
|
+
DefaultType["Float"] = "0.0";
|
|
737
|
+
DefaultType["Boolean"] = "0";
|
|
738
|
+
DefaultType["DateTime"] = "(datetime('now', 'localtime'))";
|
|
739
|
+
DefaultType["Date"] = "(date('now', 'localtime'))";
|
|
740
|
+
})(exports.DefaultType || (exports.DefaultType = {}));
|
|
1049
741
|
|
|
1050
|
-
exports.getDefaultDbConfig = getDefaultDbConfig;
|
|
1051
|
-
exports.provideDbWrapper = provideDbWrapper;
|
|
1052
|
-
exports.DbWrapperService = DbWrapperService;
|
|
1053
742
|
exports.DB_CONFIG = DB_CONFIG;
|
|
1054
743
|
exports.DB_SCHEMA = DB_SCHEMA;
|
|
1055
744
|
exports.DbWrapperModule = DbWrapperModule;
|
|
1056
|
-
exports.
|
|
1057
|
-
exports.
|
|
745
|
+
exports.DbWrapperService = DbWrapperService;
|
|
746
|
+
exports.getDefaultDbConfig = getDefaultDbConfig;
|
|
747
|
+
exports.provideDbWrapper = provideDbWrapper;
|
|
1058
748
|
|
|
1059
749
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1060
750
|
|
|
1061
751
|
})));
|
|
1062
|
-
|
|
1063
|
-
//# sourceMappingURL=db-wrapper.umd.js.map
|
|
752
|
+
//# sourceMappingURL=db-wrapper.umd.js.map
|