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.
@@ -1,227 +1,114 @@
1
- import { __awaiter, __generator } from 'tslib';
1
+ import { __decorate, __awaiter, __generator } from 'tslib';
2
2
  import { Injectable, InjectionToken, NgModule } from '@angular/core';
3
3
 
4
- /**
5
- * @fileoverview added by tsickle
6
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
7
- */
8
4
  var WindowService = /** @class */ (function () {
9
5
  function WindowService() {
10
6
  }
11
7
  Object.defineProperty(WindowService.prototype, "nativeWindow", {
12
- get: /**
13
- * @return {?}
14
- */
15
- function () {
8
+ get: function () {
16
9
  return _window();
17
10
  },
18
11
  enumerable: true,
19
12
  configurable: true
20
13
  });
21
- WindowService.decorators = [
22
- { type: Injectable }
23
- ];
14
+ WindowService = __decorate([
15
+ Injectable()
16
+ ], WindowService);
24
17
  return WindowService;
25
18
  }());
26
- /**
27
- * @return {?}
28
- */
29
19
  function _window() {
30
20
  // Return the global native browser window object
31
21
  return typeof window !== 'undefined' ? window : undefined;
32
22
  }
33
23
 
34
- /**
35
- * @fileoverview added by tsickle
36
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
37
- */
38
24
  var DbWrapperService = /** @class */ (function () {
39
25
  function DbWrapperService(dbConfig, dbSchema) {
40
26
  var _this = this;
41
27
  this._dbName = dbConfig.dbName;
42
28
  this._location = dbConfig.location || 'default';
43
29
  this._iosDatabaseLocation = dbConfig.iosDatabaseLocation || 'Library';
44
- /** @type {?} */
45
30
  var window = (new WindowService()).nativeWindow;
46
31
  if (dbSchema) {
47
32
  this.schema = dbSchema;
48
33
  }
49
- this._readyPromise = new Promise((/**
50
- * @param {?} resolve
51
- * @param {?} reject
52
- * @return {?}
53
- */
54
- function (resolve, reject) {
34
+ this._readyPromise = new Promise(function (resolve, reject) {
55
35
  if (typeof window.cordova === 'undefined') {
56
- setTimeout((/**
57
- * @return {?}
58
- */
59
- function () {
60
- _this.init(dbSchema).then((/**
61
- * @return {?}
62
- */
63
- function () {
36
+ setTimeout(function () {
37
+ _this.init(dbSchema).then(function () {
64
38
  resolve();
65
- }))
66
- .catch((/**
67
- * @param {?} err
68
- * @return {?}
69
- */
70
- function (err) {
39
+ })
40
+ .catch(function (err) {
71
41
  reject(err);
72
- }));
73
- }), 500);
42
+ });
43
+ }, 500);
74
44
  }
75
45
  else {
76
- document.addEventListener('deviceready', (/**
77
- * @return {?}
78
- */
79
- function () {
46
+ document.addEventListener('deviceready', function () {
80
47
  console.log('dbWrapper: device ready.');
81
- _this.initDevice(dbSchema).then((/**
82
- * @return {?}
83
- */
84
- function () { return resolve(); })).catch((/**
85
- * @param {?} err
86
- * @return {?}
87
- */
88
- function (err) { return reject(err); }));
89
- }));
48
+ _this.initDevice(dbSchema).then(function () { return resolve(); }).catch(function (err) { return reject(err); });
49
+ });
90
50
  }
91
- }));
51
+ });
92
52
  }
93
- /**
94
- * @return {?}
95
- */
96
- DbWrapperService.prototype.ready = /**
97
- * @return {?}
98
- */
99
- function () {
53
+ DbWrapperService.prototype.ready = function () {
100
54
  return this._readyPromise;
101
55
  };
102
- /**
103
- * @param {?} dbSchema
104
- * @return {?}
105
- */
106
- DbWrapperService.prototype.initDevice = /**
107
- * @param {?} dbSchema
108
- * @return {?}
109
- */
110
- function (dbSchema) {
56
+ DbWrapperService.prototype.initDevice = function (dbSchema) {
111
57
  var _this = this;
112
- /** @type {?} */
113
58
  var window = (new WindowService()).nativeWindow;
114
- return new Promise((/**
115
- * @param {?} resolve
116
- * @param {?} reject
117
- * @return {?}
118
- */
119
- function (resolve, reject) {
59
+ return new Promise(function (resolve, reject) {
120
60
  _this.db = window.sqlitePlugin.openDatabase({
121
61
  name: _this._dbName,
122
62
  location: _this._location,
123
63
  androidLockWorkaround: 1
124
64
  });
125
65
  if (dbSchema) {
126
- _this.generate(dbSchema).catch((/**
127
- * @param {?} err
128
- * @return {?}
129
- */
130
- function (err) {
66
+ _this.generate(dbSchema).catch(function (err) {
131
67
  reject(err);
132
- })).then((/**
133
- * @return {?}
134
- */
135
- function () { resolve(); }));
68
+ }).then(function () { resolve(); });
136
69
  }
137
70
  else {
138
71
  resolve();
139
72
  }
140
- }));
73
+ });
141
74
  };
142
- /**
143
- * @param {?} dbSchema
144
- * @return {?}
145
- */
146
- DbWrapperService.prototype.init = /**
147
- * @param {?} dbSchema
148
- * @return {?}
149
- */
150
- function (dbSchema) {
75
+ DbWrapperService.prototype.init = function (dbSchema) {
151
76
  var _this = this;
152
- /** @type {?} */
153
77
  var window = (new WindowService()).nativeWindow;
154
- return new Promise((/**
155
- * @param {?} resolve
156
- * @param {?} reject
157
- * @return {?}
158
- */
159
- function (resolve, reject) {
78
+ return new Promise(function (resolve, reject) {
160
79
  _this.db = window.openDatabase(_this._dbName, '1.0', 'database', -1);
161
80
  if (dbSchema) {
162
- _this.generate(dbSchema).catch((/**
163
- * @param {?} err
164
- * @return {?}
165
- */
166
- function (err) {
81
+ _this.generate(dbSchema).catch(function (err) {
167
82
  reject(err);
168
- })).then((/**
169
- * @return {?}
170
- */
171
- function () {
83
+ }).then(function () {
172
84
  resolve();
173
- }));
85
+ });
174
86
  }
175
87
  else {
176
88
  resolve();
177
89
  }
178
- }));
90
+ });
179
91
  };
180
- /**
181
- * @param {?} schema
182
- * @return {?}
183
- */
184
- DbWrapperService.prototype.generate = /**
185
- * @param {?} schema
186
- * @return {?}
187
- */
188
- function (schema) {
92
+ DbWrapperService.prototype.generate = function (schema) {
189
93
  var _this = this;
190
- /** @type {?} */
191
94
  var sentences = [];
192
95
  this.schema = schema;
193
96
  if (schema.tables) {
194
- schema.tables.forEach((/**
195
- * @param {?} table
196
- * @return {?}
197
- */
198
- function (table) {
97
+ schema.tables.forEach(function (table) {
199
98
  sentences.push(_this.createTable(table));
200
- }));
99
+ });
201
100
  }
202
101
  if (schema.views) {
203
- schema.views.forEach((/**
204
- * @param {?} view
205
- * @return {?}
206
- */
207
- function (view) {
102
+ schema.views.forEach(function (view) {
208
103
  sentences.push(_this.createView(view));
209
- }));
104
+ });
210
105
  }
211
106
  if (sentences.length === 0) {
212
107
  throw new Error('Esquema de la base de datos vacia.');
213
108
  }
214
109
  return Promise.all(sentences);
215
110
  };
216
- /**
217
- * @param {?} table
218
- * @return {?}
219
- */
220
- DbWrapperService.prototype.createTable = /**
221
- * @param {?} table
222
- * @return {?}
223
- */
224
- function (table) {
111
+ DbWrapperService.prototype.createTable = function (table) {
225
112
  return __awaiter(this, void 0, void 0, function () {
226
113
  var sql, onConflictPrimary, sentences, newColumns, tableDDL;
227
114
  var _this = this;
@@ -229,30 +116,21 @@ var DbWrapperService = /** @class */ (function () {
229
116
  switch (_a.label) {
230
117
  case 0:
231
118
  sql = '';
232
- sentences = [];
233
- newColumns = [];
234
- return [4 /*yield*/, this.tableExists(table.name)];
119
+ sentences = [], newColumns = [];
120
+ return [4 /*yield*/, this._tableExists(table.name)];
235
121
  case 1:
236
122
  tableDDL = _a.sent();
237
123
  if (tableDDL) {
238
- table.columns.forEach((/**
239
- * @param {?} col
240
- * @return {?}
241
- */
242
- function (col) {
243
- if (!_this.columnExists((/** @type {?} */ (tableDDL)), col.name)) {
124
+ table.columns.forEach(function (col) {
125
+ if (!_this._columnExists(tableDDL, col.name)) {
244
126
  newColumns.push(_this.addColumn(table.name, col));
245
127
  }
246
- }));
128
+ });
247
129
  }
248
130
  else {
249
- table.columns.forEach((/**
250
- * @param {?} col
251
- * @return {?}
252
- */
253
- function (col) {
131
+ table.columns.forEach(function (col) {
254
132
  sentences.push(_this.defColumn(col));
255
- }));
133
+ });
256
134
  }
257
135
  onConflictPrimary = 'on conflict fail';
258
136
  if (Array.isArray(table.primary)) {
@@ -262,238 +140,96 @@ var DbWrapperService = /** @class */ (function () {
262
140
  sentences.push(' CONSTRAINT identificador PRIMARY KEY (' + table.primary + ') ' + onConflictPrimary);
263
141
  }
264
142
  if (table.uniques) {
265
- table.uniques.forEach((/**
266
- * @param {?} uniq
267
- * @return {?}
268
- */
269
- function (uniq) {
143
+ table.uniques.forEach(function (uniq) {
270
144
  sentences.push(_this.defUnique(uniq));
271
- }));
145
+ });
272
146
  }
273
147
  if (table.foreigns) {
274
- table.foreigns.forEach((/**
275
- * @param {?} fore
276
- * @return {?}
277
- */
278
- function (fore) {
148
+ table.foreigns.forEach(function (fore) {
279
149
  sentences.push(_this.defForeign(fore));
280
- }));
150
+ });
281
151
  }
282
152
  if (tableDDL && newColumns.length !== 0) {
283
153
  return [2 /*return*/, Promise.all(newColumns)
284
- .then((/**
285
- * @return {?}
286
- */
287
- function () { console.log("Table " + table.name + " altered."); }))
288
- .catch((/**
289
- * @param {?} err
290
- * @return {?}
291
- */
292
- function (err) {
154
+ .then(function () { console.log("Table " + table.name + " altered."); })
155
+ .catch(function (err) {
293
156
  console.error("Table " + table.name + ": " + err.message);
294
157
  throw new Error("Table " + table.name + ": " + err.message);
295
- }))];
158
+ })];
296
159
  }
297
160
  else if (!tableDDL) {
298
161
  sql = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + sentences.join(',') + ')';
299
162
  return [2 /*return*/, this.query(sql)
300
- .then((/**
301
- * @return {?}
302
- */
303
- function () { console.log("Table " + table.name + " created."); }))
304
- .catch((/**
305
- * @param {?} err
306
- * @return {?}
307
- */
308
- function (err) {
163
+ .then(function () { console.log("Table " + table.name + " created."); })
164
+ .catch(function (err) {
309
165
  console.error("Table " + table.name + ": " + err.message);
310
166
  throw new Error("Table " + table.name + ": " + err.message);
311
- }))];
167
+ })];
312
168
  }
313
169
  else {
314
- return [2 /*return*/, Promise.resolve().then((/**
315
- * @return {?}
316
- */
317
- function () { console.log("Table " + table.name + " initialized."); }))];
170
+ return [2 /*return*/, Promise.resolve().then(function () { console.log("Table " + table.name + " initialized."); })];
318
171
  }
319
172
  return [2 /*return*/];
320
173
  }
321
174
  });
322
175
  });
323
176
  };
324
- /**
325
- * @param {?} view
326
- * @return {?}
327
- */
328
- DbWrapperService.prototype.createView = /**
329
- * @param {?} view
330
- * @return {?}
331
- */
332
- function (view) {
333
- /** @type {?} */
177
+ DbWrapperService.prototype.createView = function (view) {
334
178
  var sql;
335
179
  sql = 'CREATE VIEW IF NOT EXISTS ' + view.name
336
180
  + ' AS ' + view.sql;
337
181
  return this.query(sql);
338
182
  };
339
- /**
340
- * @param {?} tableName
341
- * @return {?}
342
- */
343
- DbWrapperService.prototype.getSchemaTable = /**
344
- * @param {?} tableName
345
- * @return {?}
346
- */
347
- function (tableName) {
348
- /** @type {?} */
183
+ DbWrapperService.prototype.getSchemaTable = function (tableName) {
349
184
  var res;
350
- this.schema.tables.forEach((/**
351
- * @param {?} table
352
- * @return {?}
353
- */
354
- function (table) {
185
+ this.schema.tables.forEach(function (table) {
355
186
  if (table.name === tableName) {
356
187
  res = table;
357
188
  }
358
- }));
189
+ });
359
190
  return res;
360
191
  };
361
- /**
362
- * @param {?} table
363
- * @return {?}
364
- */
365
- DbWrapperService.prototype.getUniquesTable = /**
366
- * @param {?} table
367
- * @return {?}
368
- */
369
- function (table) {
370
- /** @type {?} */
192
+ DbWrapperService.prototype.getUniquesTable = function (table) {
371
193
  var res;
372
- table.uniques.forEach((/**
373
- * @param {?} uniq
374
- * @return {?}
375
- */
376
- function (uniq) {
194
+ table.uniques.forEach(function (uniq) {
377
195
  res[uniq.name] = uniq;
378
- }));
196
+ });
379
197
  return res;
380
198
  };
381
- /**
382
- * @param {?} query
383
- * @param {?=} bindings
384
- * @return {?}
385
- */
386
- DbWrapperService.prototype.query = /**
387
- * @param {?} query
388
- * @param {?=} bindings
389
- * @return {?}
390
- */
391
- function (query, bindings) {
199
+ DbWrapperService.prototype.query = function (query, bindings) {
392
200
  var _this = this;
393
201
  if (bindings === void 0) { bindings = []; }
394
- return new Promise((/**
395
- * @param {?} resolve
396
- * @param {?} reject
397
- * @return {?}
398
- */
399
- function (resolve, reject) {
202
+ return new Promise(function (resolve, reject) {
400
203
  if (query.indexOf('select') === 0) {
401
- _this.db.readTransaction((/**
402
- * @param {?} transaction
403
- * @return {?}
404
- */
405
- function (transaction) {
406
- transaction.executeSql(query, bindings, (/**
407
- * @param {?} transaction
408
- * @param {?} result
409
- * @return {?}
410
- */
411
- function (transaction, result) {
204
+ _this.db.readTransaction(function (transaction) {
205
+ transaction.executeSql(query, bindings, function (transaction, result) {
412
206
  resolve(result);
413
- }), (/**
414
- * @param {?} transaction
415
- * @param {?} error
416
- * @return {?}
417
- */
418
- function (transaction, error) {
207
+ }, function (transaction, error) {
419
208
  reject(error);
420
- }));
421
- }), (/**
422
- * @param {?} err
423
- * @return {?}
424
- */
425
- function (err) { return reject(err); }));
209
+ });
210
+ }, function (err) { return reject(err); });
426
211
  }
427
212
  else {
428
- _this.db.transaction((/**
429
- * @param {?} transaction
430
- * @return {?}
431
- */
432
- function (transaction) {
433
- transaction.executeSql(query, bindings, (/**
434
- * @param {?} transaction
435
- * @param {?} result
436
- * @return {?}
437
- */
438
- function (transaction, result) {
213
+ _this.db.transaction(function (transaction) {
214
+ transaction.executeSql(query, bindings, function (transaction, result) {
439
215
  resolve(result);
440
- }), (/**
441
- * @param {?} transaction
442
- * @param {?} error
443
- * @return {?}
444
- */
445
- function (transaction, error) {
216
+ }, function (transaction, error) {
446
217
  reject(error);
447
- }));
448
- }), (/**
449
- * @param {?} err
450
- * @return {?}
451
- */
452
- function (err) { return reject(err); }));
218
+ });
219
+ }, function (err) { return reject(err); });
453
220
  }
454
- }));
221
+ });
455
222
  };
456
- /**
457
- * @param {?} query
458
- * @param {?=} bindings
459
- * @return {?}
460
- */
461
- DbWrapperService.prototype.Count = /**
462
- * @param {?} query
463
- * @param {?=} bindings
464
- * @return {?}
465
- */
466
- function (query, bindings) {
223
+ DbWrapperService.prototype.Count = function (query, bindings) {
467
224
  var _this = this;
468
225
  if (bindings === void 0) { bindings = []; }
469
- return this.query(query, bindings).then((/**
470
- * @param {?} rows
471
- * @return {?}
472
- */
473
- function (rows) {
226
+ return this.query(query, bindings).then(function (rows) {
474
227
  return _this.rowsCount(rows);
475
- }));
228
+ });
476
229
  };
477
- /**
478
- * @param {?} table
479
- * @param {?} bindings
480
- * @return {?}
481
- */
482
- DbWrapperService.prototype.insert = /**
483
- * @param {?} table
484
- * @param {?} bindings
485
- * @return {?}
486
- */
487
- function (table, bindings) {
230
+ DbWrapperService.prototype.insert = function (table, bindings) {
488
231
  var _this = this;
489
- /** @type {?} */
490
- var sql = '';
491
- /** @type {?} */
492
- var sqlBinds = [];
493
- /** @type {?} */
494
- var sqlKeys = [];
495
- /** @type {?} */
496
- var sqlValues = [];
232
+ var sql = '', sqlBinds = [], sqlKeys = [], sqlValues = [];
497
233
  sql = sql + 'insert into ' + table + ' ';
498
234
  for (var index in bindings) {
499
235
  if (bindings.hasOwnProperty(index)) {
@@ -503,61 +239,22 @@ var DbWrapperService = /** @class */ (function () {
503
239
  }
504
240
  }
505
241
  sql = sql + '(' + sqlKeys.join(',') + ') values (' + sqlBinds.join(',') + ')';
506
- return new Promise((/**
507
- * @param {?} resolve
508
- * @param {?} reject
509
- * @return {?}
510
- */
511
- function (resolve, reject) {
512
- _this.db.transaction((/**
513
- * @param {?} transaction
514
- * @return {?}
515
- */
516
- function (transaction) {
517
- transaction.executeSql(sql, sqlValues, (/**
518
- * @param {?} transaction
519
- * @param {?} result
520
- * @return {?}
521
- */
522
- function (transaction, result) {
242
+ return new Promise(function (resolve, reject) {
243
+ _this.db.transaction(function (transaction) {
244
+ transaction.executeSql(sql, sqlValues, function (transaction, result) {
523
245
  resolve(result);
524
- }), (/**
525
- * @param {?} transaction
526
- * @param {?} error
527
- * @return {?}
528
- */
529
- function (transaction, error) {
246
+ }, function (transaction, error) {
530
247
  reject(error);
531
- }));
532
- }));
533
- }));
248
+ });
249
+ });
250
+ });
534
251
  };
535
- /**
536
- * @param {?} table
537
- * @param {?} bindings
538
- * @param {?} where
539
- * @return {?}
540
- */
541
- DbWrapperService.prototype.update = /**
542
- * @param {?} table
543
- * @param {?} bindings
544
- * @param {?} where
545
- * @return {?}
546
- */
547
- function (table, bindings, where) {
252
+ DbWrapperService.prototype.update = function (table, bindings, where) {
548
253
  var _this = this;
549
- /** @type {?} */
550
- var sql = '';
551
- /** @type {?} */
552
- var sqlBinds = [];
553
- /** @type {?} */
554
- var sqlKeys = [];
555
- /** @type {?} */
556
- var sqlValues = [];
254
+ var sql = '', sqlBinds = [], sqlKeys = [], sqlValues = [];
557
255
  sql = sql + 'update ' + table + ' set ';
558
256
  for (var index in bindings) {
559
257
  if (bindings.hasOwnProperty(index)) {
560
- /** @type {?} */
561
258
  var newObj = bindings[index];
562
259
  if (typeof newObj === 'object' && newObj !== null) {
563
260
  sqlValues.push(newObj.value);
@@ -590,118 +287,53 @@ var DbWrapperService = /** @class */ (function () {
590
287
  }
591
288
  }
592
289
  sql = sql + sqlBinds.join(',') + ' where ' + sqlKeys.join(' and ');
593
- return new Promise((/**
594
- * @param {?} resolve
595
- * @param {?} reject
596
- * @return {?}
597
- */
598
- function (resolve, reject) {
599
- _this.db.transaction((/**
600
- * @param {?} transaction
601
- * @return {?}
602
- */
603
- function (transaction) {
604
- transaction.executeSql(sql, sqlValues, (/**
605
- * @param {?} transaction
606
- * @param {?} result
607
- * @return {?}
608
- */
609
- function (transaction, result) {
290
+ return new Promise(function (resolve, reject) {
291
+ _this.db.transaction(function (transaction) {
292
+ transaction.executeSql(sql, sqlValues, function (transaction, result) {
610
293
  resolve(result);
611
- }), (/**
612
- * @param {?} transaction
613
- * @param {?} error
614
- * @return {?}
615
- */
616
- function (transaction, error) {
294
+ }, function (transaction, error) {
617
295
  reject(error);
618
- }));
619
- }));
620
- }));
296
+ });
297
+ });
298
+ });
621
299
  };
622
- /**
623
- * @param {?} tables
624
- * @return {?}
625
- */
626
- DbWrapperService.prototype.dropTable = /**
627
- * @param {?} tables
628
- * @return {?}
629
- */
630
- function (tables) {
300
+ DbWrapperService.prototype.dropTable = function (tables) {
631
301
  var _this = this;
632
- /** @type {?} */
633
302
  var cont = 1;
634
303
  cont = tables.length;
635
- return new Promise((/**
636
- * @param {?} resolve
637
- * @param {?} reject
638
- * @return {?}
639
- */
640
- function (resolve, reject) {
641
- tables.some((/**
642
- * @param {?} table
643
- * @return {?}
644
- */
645
- function (table) {
304
+ return new Promise(function (resolve, reject) {
305
+ tables.some(function (table) {
646
306
  if (cont !== 0) {
647
307
  _this.query('DROP TABLE ' + table)
648
- .then((/**
649
- * @return {?}
650
- */
651
- function () {
308
+ .then(function () {
652
309
  if (cont === 1) {
653
310
  resolve();
654
311
  }
655
312
  else {
656
313
  cont--;
657
314
  }
658
- }), (/**
659
- * @param {?} err
660
- * @return {?}
661
- */
662
- function (err) {
315
+ }, function (err) {
663
316
  cont = 0;
664
317
  reject(err);
665
318
  return true;
666
- }));
319
+ });
667
320
  return false;
668
321
  }
669
- }));
670
- }));
322
+ });
323
+ });
671
324
  };
672
- /**
673
- * @param {?} result
674
- * @return {?}
675
- */
676
- DbWrapperService.prototype.fetchAll = /**
677
- * @param {?} result
678
- * @return {?}
679
- */
680
- function (result) {
681
- /** @type {?} */
325
+ DbWrapperService.prototype.fetchAll = function (result) {
682
326
  var output = [];
683
327
  for (var i = 0; i < result.rows.length; i++) {
684
328
  output.push(result.rows.item(i));
685
329
  }
686
330
  return output;
687
331
  };
688
- /**
689
- * @param {?} result
690
- * @return {?}
691
- */
692
- DbWrapperService.prototype.fetch = /**
693
- * @param {?} result
694
- * @return {?}
695
- */
696
- function (result) {
697
- /** @type {?} */
698
- var objeto = undefined;
699
- /** @type {?} */
700
- var newObj = undefined;
332
+ DbWrapperService.prototype.fetch = function (result) {
333
+ var objeto = undefined, newObj = undefined;
701
334
  if (result.rows.length !== 0) {
702
335
  objeto = result.rows.item(0);
703
336
  newObj = {};
704
- /** @type {?} */
705
337
  var keys = Object.keys(objeto);
706
338
  for (var key in keys) {
707
339
  newObj[keys[key]] = objeto[keys[key]];
@@ -709,32 +341,29 @@ var DbWrapperService = /** @class */ (function () {
709
341
  }
710
342
  return newObj;
711
343
  };
712
- /**
713
- * @param {?} result
714
- * @return {?}
715
- */
716
- DbWrapperService.prototype.rowsCount = /**
717
- * @param {?} result
718
- * @return {?}
719
- */
720
- function (result) {
344
+ DbWrapperService.prototype.rowsCount = function (result) {
721
345
  return result.rows.length;
722
346
  };
347
+ DbWrapperService.prototype.tableExists = function (table) {
348
+ var _this = this;
349
+ return this.query('select sql from sqlite_master ' +
350
+ 'where type=\'table\' and name=\'' + table + '\'')
351
+ .then(function (result) { return (_this.rowsCount(result) === 1); });
352
+ };
353
+ DbWrapperService.prototype.columnExists = function (table, column) {
354
+ var _this = this;
355
+ return this._tableExists(table)
356
+ .then(function (tableDDL) {
357
+ if (tableDDL) {
358
+ return _this._columnExists(tableDDL, column);
359
+ }
360
+ else {
361
+ return false;
362
+ }
363
+ });
364
+ };
723
365
  /* Private */
724
- /* Private */
725
- /**
726
- * @private
727
- * @param {?} col
728
- * @return {?}
729
- */
730
- DbWrapperService.prototype.defColumn = /* Private */
731
- /**
732
- * @private
733
- * @param {?} col
734
- * @return {?}
735
- */
736
- function (col) {
737
- /** @type {?} */
366
+ DbWrapperService.prototype.defColumn = function (col) {
738
367
  var colSql;
739
368
  colSql = col.name + ' ' + col.type;
740
369
  if (!col.isNullable) {
@@ -752,22 +381,10 @@ var DbWrapperService = /** @class */ (function () {
752
381
  }
753
382
  return colSql;
754
383
  };
755
- /**
756
- * @private
757
- * @param {?} unique
758
- * @return {?}
759
- */
760
- DbWrapperService.prototype.defUnique = /**
761
- * @private
762
- * @param {?} unique
763
- * @return {?}
764
- */
765
- function (unique) {
766
- /** @type {?} */
384
+ DbWrapperService.prototype.defUnique = function (unique) {
767
385
  var uniqSql;
768
386
  // depende del entorno, producción o desarrollo
769
- /** @type {?} */
770
- var onConflictUnique = 'on conflict fail';
387
+ var onConflictUnique = 'on conflict replace';
771
388
  if (Array.isArray(unique.fields)) {
772
389
  uniqSql = " CONSTRAINT " + unique.name + " UNIQUE ( " + unique.fields.join(',') + " ) " + onConflictUnique + " ";
773
390
  }
@@ -776,18 +393,7 @@ var DbWrapperService = /** @class */ (function () {
776
393
  }
777
394
  return uniqSql;
778
395
  };
779
- /**
780
- * @private
781
- * @param {?} fore
782
- * @return {?}
783
- */
784
- DbWrapperService.prototype.defForeign = /**
785
- * @private
786
- * @param {?} fore
787
- * @return {?}
788
- */
789
- function (fore) {
790
- /** @type {?} */
396
+ DbWrapperService.prototype.defForeign = function (fore) {
791
397
  var foreSql;
792
398
  if (Array.isArray(fore.foreignKey)) {
793
399
  foreSql = " FOREIGN KEY ( " + fore.foreignKey.join(',') + " ) ";
@@ -803,46 +409,20 @@ var DbWrapperService = /** @class */ (function () {
803
409
  }
804
410
  return foreSql;
805
411
  };
806
- /**
807
- * @private
808
- * @param {?} table
809
- * @return {?}
810
- */
811
- DbWrapperService.prototype.tableExists = /**
812
- * @private
813
- * @param {?} table
814
- * @return {?}
815
- */
816
- function (table) {
412
+ DbWrapperService.prototype._tableExists = function (table) {
817
413
  var _this = this;
818
414
  return this.query('select sql from sqlite_master ' +
819
415
  'where type=\'table\' and name=\'' + table + '\'')
820
- .then((/**
821
- * @param {?} result
822
- * @return {?}
823
- */
824
- function (result) {
416
+ .then(function (result) {
825
417
  if (_this.rowsCount(result) === 1) {
826
- return (/** @type {?} */ (((/** @type {?} */ (_this.fetch(result)))).sql));
418
+ return _this.fetch(result).sql;
827
419
  }
828
420
  else {
829
421
  return false;
830
422
  }
831
- }));
423
+ });
832
424
  };
833
- /**
834
- * @private
835
- * @param {?} tableDDL
836
- * @param {?} column
837
- * @return {?}
838
- */
839
- DbWrapperService.prototype.columnExists = /**
840
- * @private
841
- * @param {?} tableDDL
842
- * @param {?} column
843
- * @return {?}
844
- */
845
- function (tableDDL, column) {
425
+ DbWrapperService.prototype._columnExists = function (tableDDL, column) {
846
426
  if (tableDDL.indexOf(column) === -1) {
847
427
  return false;
848
428
  }
@@ -850,34 +430,15 @@ var DbWrapperService = /** @class */ (function () {
850
430
  return true;
851
431
  }
852
432
  };
853
- /**
854
- * @private
855
- * @param {?} table
856
- * @param {?} col
857
- * @return {?}
858
- */
859
- DbWrapperService.prototype.addColumn = /**
860
- * @private
861
- * @param {?} table
862
- * @param {?} col
863
- * @return {?}
864
- */
865
- function (table, col) {
866
- /** @type {?} */
433
+ DbWrapperService.prototype.addColumn = function (table, col) {
867
434
  var colSql = this.defColumn(col);
868
- /** @type {?} */
869
435
  var query = 'alter TABLE ' + table + ' add COLUMN ' + colSql;
870
436
  return this.query(query);
871
437
  };
872
438
  return DbWrapperService;
873
439
  }());
874
- /** @type {?} */
875
440
  var DB_CONFIG = new InjectionToken('dbWrapperConfig');
876
- /** @type {?} */
877
441
  var DB_SCHEMA = new InjectionToken('dbWrapperSchema');
878
- /**
879
- * @return {?}
880
- */
881
442
  function getDefaultDbConfig() {
882
443
  return {
883
444
  dbName: 'db.sqlite',
@@ -885,37 +446,18 @@ function getDefaultDbConfig() {
885
446
  iosDatabaseLocation: 'Library'
886
447
  };
887
448
  }
888
- /**
889
- * @param {?} dbConfig
890
- * @param {?=} dbSchema
891
- * @return {?}
892
- */
893
449
  function provideDbWrapper(dbConfig, dbSchema) {
894
- /** @type {?} */
895
450
  var config = !!dbConfig ? dbConfig : getDefaultDbConfig();
896
451
  return new DbWrapperService(config, dbSchema);
897
452
  }
898
453
 
899
- /**
900
- * @fileoverview added by tsickle
901
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
902
- */
903
454
  var DbWrapperModule = /** @class */ (function () {
904
455
  function DbWrapperModule() {
905
456
  }
906
- /**
907
- * @param {?} dbConfig
908
- * @param {?=} schema
909
- * @return {?}
910
- */
911
- DbWrapperModule.forRoot = /**
912
- * @param {?} dbConfig
913
- * @param {?=} schema
914
- * @return {?}
915
- */
916
- function (dbConfig, schema) {
457
+ DbWrapperModule_1 = DbWrapperModule;
458
+ DbWrapperModule.forRoot = function (dbConfig, schema) {
917
459
  return {
918
- ngModule: DbWrapperModule,
460
+ ngModule: DbWrapperModule_1,
919
461
  providers: [
920
462
  { provide: DB_CONFIG, useValue: dbConfig },
921
463
  { provide: DB_SCHEMA, useValue: schema },
@@ -923,71 +465,65 @@ var DbWrapperModule = /** @class */ (function () {
923
465
  ]
924
466
  };
925
467
  };
926
- DbWrapperModule.decorators = [
927
- { type: NgModule }
928
- ];
468
+ var DbWrapperModule_1;
469
+ DbWrapperModule = DbWrapperModule_1 = __decorate([
470
+ NgModule()
471
+ ], DbWrapperModule);
929
472
  return DbWrapperModule;
930
473
  }());
931
474
 
932
- /**
933
- * @fileoverview added by tsickle
934
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
935
- */
936
- /** @enum {string} */
937
- var DataType = {
938
- Integer: 'integer',
939
- Int: 'integer',
940
- TinyInt: 'integer',
941
- SmallInt: 'integer',
942
- BigInt: 'integer',
943
- Text: 'text',
944
- Char: 'text',
945
- NChar: 'text',
946
- VarChar: 'text',
947
- NVarChar: 'text',
948
- CLOB: 'text',
949
- BLOB: 'blob',
950
- Real: 'real',
951
- Double: 'real',
952
- Decimal: 'real',
953
- Float: 'real',
954
- Boolean: 'integer',
955
- DateTime: 'text',
956
- Date: 'text',
957
- };
958
- /** @enum {string} */
959
- var DefaultType = {
960
- Integer: '0',
961
- Int: '0',
962
- TinyInt: '0',
963
- SmallInt: '0',
964
- BigInt: '0',
965
- Text: '\'\'',
966
- Char: '\'\'',
967
- NChar: '\'\'',
968
- VarChar: '\'\'',
969
- NVarChar: '\'\'',
970
- CLOB: '\'\'',
971
- BLOB: '0',
972
- Real: '0.0',
973
- Double: '0.0',
974
- Decimal: '0.0',
975
- Float: '0.0',
976
- Boolean: '0',
977
- DateTime: '(datetime(\'now\', \'localtime\'))',
978
- Date: '(date(\'now\', \'localtime\'))',
979
- };
475
+ var DataType;
476
+ (function (DataType) {
477
+ DataType["Integer"] = "integer";
478
+ DataType["Int"] = "integer";
479
+ DataType["TinyInt"] = "integer";
480
+ DataType["SmallInt"] = "integer";
481
+ DataType["BigInt"] = "integer";
482
+ DataType["Text"] = "text";
483
+ DataType["Char"] = "text";
484
+ DataType["NChar"] = "text";
485
+ DataType["VarChar"] = "text";
486
+ DataType["NVarChar"] = "text";
487
+ DataType["CLOB"] = "text";
488
+ DataType["BLOB"] = "blob";
489
+ DataType["Real"] = "real";
490
+ DataType["Double"] = "real";
491
+ DataType["Decimal"] = "real";
492
+ DataType["Float"] = "real";
493
+ DataType["Boolean"] = "integer";
494
+ DataType["DateTime"] = "text";
495
+ DataType["Date"] = "text";
496
+ })(DataType || (DataType = {}));
497
+ var DefaultType;
498
+ (function (DefaultType) {
499
+ DefaultType["Integer"] = "0";
500
+ DefaultType["Int"] = "0";
501
+ DefaultType["TinyInt"] = "0";
502
+ DefaultType["SmallInt"] = "0";
503
+ DefaultType["BigInt"] = "0";
504
+ DefaultType["Text"] = "''";
505
+ DefaultType["Char"] = "''";
506
+ DefaultType["NChar"] = "''";
507
+ DefaultType["VarChar"] = "''";
508
+ DefaultType["NVarChar"] = "''";
509
+ DefaultType["CLOB"] = "''";
510
+ DefaultType["BLOB"] = "0";
511
+ DefaultType["Real"] = "0.0";
512
+ DefaultType["Double"] = "0.0";
513
+ DefaultType["Decimal"] = "0.0";
514
+ DefaultType["Float"] = "0.0";
515
+ DefaultType["Boolean"] = "0";
516
+ DefaultType["DateTime"] = "(datetime('now', 'localtime'))";
517
+ DefaultType["Date"] = "(date('now', 'localtime'))";
518
+ })(DefaultType || (DefaultType = {}));
980
519
 
981
- /**
982
- * @fileoverview added by tsickle
983
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
520
+ /*
521
+ * Public API Surface of db-wrapper
984
522
  */
985
523
 
986
524
  /**
987
- * @fileoverview added by tsickle
988
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
525
+ * Generated bundle index. Do not edit.
989
526
  */
990
527
 
991
- export { getDefaultDbConfig, provideDbWrapper, DbWrapperService, DB_CONFIG, DB_SCHEMA, DbWrapperModule, DataType, DefaultType };
992
-
993
- //# sourceMappingURL=db-wrapper.js.map
528
+ export { DB_CONFIG, DB_SCHEMA, DataType, DbWrapperModule, DbWrapperService, DefaultType, getDefaultDbConfig, provideDbWrapper };
529
+ //# sourceMappingURL=db-wrapper.js.map