db-wrapper 0.0.7 → 2.0.0

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.
Files changed (40) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +24 -24
  3. package/esm2020/db-wrapper.mjs +5 -0
  4. package/esm2020/lib/db-wrapper.models.mjs +45 -0
  5. package/esm2020/lib/db-wrapper.module.mjs +22 -0
  6. package/esm2020/lib/db-wrapper.service.mjs +405 -0
  7. package/esm2020/lib/window.service.mjs +17 -0
  8. package/esm2020/public-api.mjs +7 -0
  9. package/fesm2015/db-wrapper.mjs +498 -0
  10. package/fesm2015/db-wrapper.mjs.map +1 -0
  11. package/fesm2020/db-wrapper.mjs +495 -0
  12. package/fesm2020/db-wrapper.mjs.map +1 -0
  13. package/{db-wrapper.d.ts → index.d.ts} +5 -4
  14. package/lib/db-wrapper.models.d.ts +119 -119
  15. package/lib/db-wrapper.module.d.ts +9 -5
  16. package/lib/db-wrapper.service.d.ts +39 -37
  17. package/lib/window.service.d.ts +6 -3
  18. package/package.json +26 -16
  19. package/public-api.d.ts +3 -3
  20. package/bundles/db-wrapper.umd.js +0 -1063
  21. package/bundles/db-wrapper.umd.js.map +0 -1
  22. package/bundles/db-wrapper.umd.min.js +0 -2
  23. package/bundles/db-wrapper.umd.min.js.map +0 -1
  24. package/db-wrapper.metadata.json +0 -1
  25. package/esm2015/db-wrapper.js +0 -9
  26. package/esm2015/lib/db-wrapper.models.js +0 -206
  27. package/esm2015/lib/db-wrapper.module.js +0 -27
  28. package/esm2015/lib/db-wrapper.service.js +0 -779
  29. package/esm2015/lib/window.service.js +0 -24
  30. package/esm2015/public-api.js +0 -11
  31. package/esm5/db-wrapper.js +0 -9
  32. package/esm5/lib/db-wrapper.models.js +0 -206
  33. package/esm5/lib/db-wrapper.module.js +0 -36
  34. package/esm5/lib/db-wrapper.service.js +0 -895
  35. package/esm5/lib/window.service.js +0 -32
  36. package/esm5/public-api.js +0 -11
  37. package/fesm2015/db-wrapper.js +0 -863
  38. package/fesm2015/db-wrapper.js.map +0 -1
  39. package/fesm5/db-wrapper.js +0 -993
  40. package/fesm5/db-wrapper.js.map +0 -1
@@ -1,1063 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
3
- typeof define === 'function' && define.amd ? define('db-wrapper', ['exports', '@angular/core'], factory) :
4
- (factory((global['db-wrapper'] = {}),global.ng.core));
5
- }(this, (function (exports,core) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation. All rights reserved.
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
12
-
13
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
- MERCHANTABLITY OR NON-INFRINGEMENT.
17
-
18
- See the Apache Version 2.0 License for specific language governing permissions
19
- and limitations under the License.
20
- ***************************************************************************** */
21
- function __awaiter(thisArg, _arguments, P, generator) {
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try {
24
- step(generator.next(value));
25
- }
26
- catch (e) {
27
- reject(e);
28
- } }
29
- function rejected(value) { try {
30
- step(generator["throw"](value));
31
- }
32
- catch (e) {
33
- reject(e);
34
- } }
35
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- }
39
- function __generator(thisArg, body) {
40
- var _ = { label: 0, sent: function () { if (t[0] & 1)
41
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
42
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
43
- function verb(n) { return function (v) { return step([n, v]); }; }
44
- function step(op) {
45
- if (f)
46
- throw new TypeError("Generator is already executing.");
47
- while (_)
48
- try {
49
- 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)
50
- return t;
51
- if (y = 0, t)
52
- op = [op[0] & 2, t.value];
53
- switch (op[0]) {
54
- case 0:
55
- case 1:
56
- t = op;
57
- break;
58
- case 4:
59
- _.label++;
60
- return { value: op[1], done: false };
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, _);
95
- }
96
- catch (e) {
97
- op = [6, e];
98
- y = 0;
99
- }
100
- finally {
101
- f = t = 0;
102
- }
103
- if (op[0] & 5)
104
- throw op[1];
105
- return { value: op[0] ? op[1] : void 0, done: true };
106
- }
107
- }
108
-
109
- /**
110
- * @fileoverview added by tsickle
111
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
112
- */
113
- var WindowService = /** @class */ (function () {
114
- function WindowService() {
115
- }
116
- Object.defineProperty(WindowService.prototype, "nativeWindow", {
117
- get: /**
118
- * @return {?}
119
- */ function () {
120
- return _window();
121
- },
122
- enumerable: true,
123
- configurable: true
124
- });
125
- WindowService.decorators = [
126
- { type: core.Injectable }
127
- ];
128
- return WindowService;
129
- }());
130
- /**
131
- * @return {?}
132
- */
133
- function _window() {
134
- // Return the global native browser window object
135
- return typeof window !== 'undefined' ? window : undefined;
136
- }
137
-
138
- /**
139
- * @fileoverview added by tsickle
140
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
141
- */
142
- var DbWrapperService = /** @class */ (function () {
143
- function DbWrapperService(dbConfig, dbSchema) {
144
- var _this = this;
145
- this._dbName = dbConfig.dbName;
146
- this._location = dbConfig.location || 'default';
147
- this._iosDatabaseLocation = dbConfig.iosDatabaseLocation || 'Library';
148
- /** @type {?} */
149
- var window = (new WindowService()).nativeWindow;
150
- if (dbSchema) {
151
- this.schema = dbSchema;
152
- }
153
- this._readyPromise = new Promise(( /**
154
- * @param {?} resolve
155
- * @param {?} reject
156
- * @return {?}
157
- */function (resolve, reject) {
158
- if (typeof window.cordova === 'undefined') {
159
- setTimeout(( /**
160
- * @return {?}
161
- */function () {
162
- _this.init(dbSchema).then(( /**
163
- * @return {?}
164
- */function () {
165
- resolve();
166
- }))
167
- .catch(( /**
168
- * @param {?} err
169
- * @return {?}
170
- */function (err) {
171
- reject(err);
172
- }));
173
- }), 500);
174
- }
175
- else {
176
- document.addEventListener('deviceready', ( /**
177
- * @return {?}
178
- */function () {
179
- 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
220
- });
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
- }
292
- if (schema.views) {
293
- schema.views.forEach(( /**
294
- * @param {?} view
295
- * @return {?}
296
- */function (view) {
297
- sentences.push(_this.createView(view));
298
- }));
299
- }
300
- if (sentences.length === 0) {
301
- throw new Error('Esquema de la base de datos vacia.');
302
- }
303
- return Promise.all(sentences);
304
- };
305
- /**
306
- * @param {?} table
307
- * @return {?}
308
- */
309
- DbWrapperService.prototype.createTable = /**
310
- * @param {?} table
311
- * @return {?}
312
- */
313
- function (table) {
314
- return __awaiter(this, void 0, void 0, function () {
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
- }
401
- });
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
- }
542
- return this.query(query, bindings).then(( /**
543
- * @param {?} rows
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
- }
576
- }
577
- sql = sql + '(' + sqlKeys.join(',') + ') values (' + sqlBinds.join(',') + ')';
578
- return new Promise(( /**
579
- * @param {?} resolve
580
- * @param {?} reject
581
- * @return {?}
582
- */function (resolve, reject) {
583
- _this.db.transaction(( /**
584
- * @param {?} transaction
585
- * @return {?}
586
- */function (transaction) {
587
- transaction.executeSql(sql, sqlValues, ( /**
588
- * @param {?} transaction
589
- * @param {?} result
590
- * @return {?}
591
- */function (transaction, result) {
592
- resolve(result);
593
- }), ( /**
594
- * @param {?} transaction
595
- * @param {?} error
596
- * @return {?}
597
- */function (transaction, error) {
598
- reject(error);
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) {
616
- var _this = this;
617
- /** @type {?} */
618
- var sql = '';
619
- /** @type {?} */
620
- var sqlBinds = [];
621
- /** @type {?} */
622
- var sqlKeys = [];
623
- /** @type {?} */
624
- var sqlValues = [];
625
- sql = sql + 'update ' + table + ' set ';
626
- for (var index in bindings) {
627
- if (bindings.hasOwnProperty(index)) {
628
- /** @type {?} */
629
- var newObj = bindings[index];
630
- if (typeof newObj === 'object' && newObj !== null) {
631
- sqlValues.push(newObj.value);
632
- if (newObj.ifnull) {
633
- sqlBinds.push(index + ' = ifnull( ' + index + ',0) + ?');
634
- }
635
- else if (newObj.operator) {
636
- sqlBinds.push(index + ' = ' + index + newObj.operator + ' ?');
637
- }
638
- else {
639
- sqlBinds.push(index + ' = ?');
640
- }
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
- }
658
- }
659
- }
660
- sql = sql + sqlBinds.join(',') + ' where ' + sqlKeys.join(' and ');
661
- return new Promise(( /**
662
- * @param {?} resolve
663
- * @param {?} reject
664
- * @return {?}
665
- */function (resolve, reject) {
666
- _this.db.transaction(( /**
667
- * @param {?} transaction
668
- * @return {?}
669
- */function (transaction) {
670
- transaction.executeSql(sql, sqlValues, ( /**
671
- * @param {?} transaction
672
- * @param {?} result
673
- * @return {?}
674
- */function (transaction, result) {
675
- resolve(result);
676
- }), ( /**
677
- * @param {?} transaction
678
- * @param {?} error
679
- * @return {?}
680
- */function (transaction, error) {
681
- 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
- }
769
- }
770
- return newObj;
771
- };
772
- /**
773
- * @param {?} result
774
- * @return {?}
775
- */
776
- DbWrapperService.prototype.rowsCount = /**
777
- * @param {?} result
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 ';
802
- }
803
- if (col.default) {
804
- colSql += ' DEFAULT ' + col.default + ' ';
805
- }
806
- if (col.type === 'text' && col.length) {
807
- colSql += " CONSTRAINT " + col.name + "_length CHECK ( ";
808
- if (col.isNullable) {
809
- colSql += col.name + " is null OR ";
810
- }
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
- }
864
- return foreSql;
865
- };
866
- /**
867
- * @private
868
- * @param {?} table
869
- * @return {?}
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));
886
- }
887
- else {
888
- return false;
889
- }
890
- }));
891
- };
892
- /**
893
- * @private
894
- * @param {?} tableDDL
895
- * @param {?} column
896
- * @return {?}
897
- */
898
- DbWrapperService.prototype.columnExists = /**
899
- * @private
900
- * @param {?} tableDDL
901
- * @param {?} column
902
- * @return {?}
903
- */
904
- function (tableDDL, column) {
905
- if (tableDDL.indexOf(column) === -1) {
906
- return false;
907
- }
908
- else {
909
- return true;
910
- }
911
- };
912
- /**
913
- * @private
914
- * @param {?} table
915
- * @param {?} col
916
- * @return {?}
917
- */
918
- DbWrapperService.prototype.addColumn = /**
919
- * @private
920
- * @param {?} table
921
- * @param {?} col
922
- * @return {?}
923
- */
924
- function (table, col) {
925
- /** @type {?} */
926
- var colSql = this.defColumn(col);
927
- /** @type {?} */
928
- var query = 'alter TABLE ' + table + ' add COLUMN ' + colSql;
929
- return this.query(query);
930
- };
931
- return DbWrapperService;
932
- }());
933
- /** @type {?} */
934
- var DB_CONFIG = new core.InjectionToken('dbWrapperConfig');
935
- /** @type {?} */
936
- var DB_SCHEMA = new core.InjectionToken('dbWrapperSchema');
937
- /**
938
- * @return {?}
939
- */
940
- function getDefaultDbConfig() {
941
- return {
942
- dbName: 'db.sqlite',
943
- location: 'default',
944
- iosDatabaseLocation: 'Library'
945
- };
946
- }
947
- /**
948
- * @param {?} dbConfig
949
- * @param {?=} dbSchema
950
- * @return {?}
951
- */
952
- function provideDbWrapper(dbConfig, dbSchema) {
953
- /** @type {?} */
954
- var config = !!dbConfig ? dbConfig : getDefaultDbConfig();
955
- return new DbWrapperService(config, dbSchema);
956
- }
957
-
958
- /**
959
- * @fileoverview added by tsickle
960
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
961
- */
962
- var DbWrapperModule = /** @class */ (function () {
963
- function DbWrapperModule() {
964
- }
965
- /**
966
- * @param {?} dbConfig
967
- * @param {?=} schema
968
- * @return {?}
969
- */
970
- DbWrapperModule.forRoot = /**
971
- * @param {?} dbConfig
972
- * @param {?=} schema
973
- * @return {?}
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
- };
984
- };
985
- DbWrapperModule.decorators = [
986
- { type: core.NgModule }
987
- ];
988
- return DbWrapperModule;
989
- }());
990
-
991
- /**
992
- * @fileoverview added by tsickle
993
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
994
- */
995
- /** @enum {string} */
996
- var DataType = {
997
- Integer: 'integer',
998
- Int: 'integer',
999
- TinyInt: 'integer',
1000
- SmallInt: 'integer',
1001
- BigInt: 'integer',
1002
- Text: 'text',
1003
- Char: 'text',
1004
- NChar: 'text',
1005
- VarChar: 'text',
1006
- NVarChar: 'text',
1007
- CLOB: 'text',
1008
- BLOB: 'blob',
1009
- Real: 'real',
1010
- Double: 'real',
1011
- Decimal: 'real',
1012
- Float: 'real',
1013
- Boolean: 'integer',
1014
- DateTime: 'text',
1015
- Date: 'text',
1016
- };
1017
- /** @enum {string} */
1018
- var DefaultType = {
1019
- Integer: '0',
1020
- Int: '0',
1021
- TinyInt: '0',
1022
- SmallInt: '0',
1023
- BigInt: '0',
1024
- Text: '\'\'',
1025
- Char: '\'\'',
1026
- NChar: '\'\'',
1027
- VarChar: '\'\'',
1028
- NVarChar: '\'\'',
1029
- CLOB: '\'\'',
1030
- BLOB: '0',
1031
- Real: '0.0',
1032
- Double: '0.0',
1033
- Decimal: '0.0',
1034
- Float: '0.0',
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
- */
1049
-
1050
- exports.getDefaultDbConfig = getDefaultDbConfig;
1051
- exports.provideDbWrapper = provideDbWrapper;
1052
- exports.DbWrapperService = DbWrapperService;
1053
- exports.DB_CONFIG = DB_CONFIG;
1054
- exports.DB_SCHEMA = DB_SCHEMA;
1055
- exports.DbWrapperModule = DbWrapperModule;
1056
- exports.DataType = DataType;
1057
- exports.DefaultType = DefaultType;
1058
-
1059
- Object.defineProperty(exports, '__esModule', { value: true });
1060
-
1061
- })));
1062
-
1063
- //# sourceMappingURL=db-wrapper.umd.js.map