ngx-universal-zone 0.0.1
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/database/db-base.service.d.ts +37 -0
- package/database/db-setting-constant.d.ts +7 -0
- package/database/db-sql.service.d.ts +48 -0
- package/database/db-web.service.d.ts +50 -0
- package/database/db.module.d.ts +6 -0
- package/database/index.d.ts +6 -0
- package/database/schema.service.d.ts +25 -0
- package/fesm2022/ngx-universal-zone-database.mjs +608 -0
- package/fesm2022/ngx-universal-zone-database.mjs.map +1 -0
- package/fesm2022/ngx-universal-zone-pipes.mjs +87 -0
- package/fesm2022/ngx-universal-zone-pipes.mjs.map +1 -0
- package/fesm2022/ngx-universal-zone-pub-sub.mjs +147 -0
- package/fesm2022/ngx-universal-zone-pub-sub.mjs.map +1 -0
- package/fesm2022/ngx-universal-zone-ui.mjs +218 -0
- package/fesm2022/ngx-universal-zone-ui.mjs.map +1 -0
- package/fesm2022/ngx-universal-zone.mjs +966 -0
- package/fesm2022/ngx-universal-zone.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/package.json +40 -0
- package/pipes/formateDate.pipe.d.ts +8 -0
- package/pipes/index.d.ts +2 -0
- package/pipes/safe.pipe.d.ts +18 -0
- package/pub-sub/i-hash.d.ts +10 -0
- package/pub-sub/index.d.ts +2 -0
- package/pub-sub/ngx-pub-sub.module.d.ts +7 -0
- package/pub-sub/ngx-pub-sub.service.d.ts +27 -0
- package/pub-sub/subject-type.enum.d.ts +5 -0
- package/public-api.d.ts +6 -0
- package/shared/app-injector.d.ts +6 -0
- package/shared/app-setting.service.d.ts +18 -0
- package/shared/flag-based-preloading-strategy.d.ts +12 -0
- package/shared/helper.service.d.ts +15 -0
- package/shared/message-bus/index.d.ts +4 -0
- package/shared/message-bus/message-bus.d.ts +15 -0
- package/shared/message-bus/message-bus.testing.d.ts +9 -0
- package/shared/message-bus/messages.d.ts +2 -0
- package/shared/message-bus/models.d.ts +39 -0
- package/shared/universal-zone.module.d.ts +2 -0
- package/ui/directives/directives.module.d.ts +9 -0
- package/ui/directives/long-ress.directive.d.ts +21 -0
- package/ui/directives/only-number.directive.d.ts +7 -0
- package/ui/index.d.ts +5 -0
- package/ui/no-data/no-data.component.d.ts +13 -0
- package/ui/no-data/no-data.module.d.ts +8 -0
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
import { Observable, Subject, switchMap, of, forkJoin } from 'rxjs';
|
|
2
|
+
import Dexie from 'dexie';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { Injectable, makeEnvironmentProviders } from '@angular/core';
|
|
5
|
+
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
class DbServiceConfig {
|
|
8
|
+
}
|
|
9
|
+
var DbServiceType;
|
|
10
|
+
(function (DbServiceType) {
|
|
11
|
+
DbServiceType[DbServiceType["IndexDd"] = 0] = "IndexDd";
|
|
12
|
+
DbServiceType[DbServiceType["Sqlite"] = 1] = "Sqlite";
|
|
13
|
+
})(DbServiceType || (DbServiceType = {}));
|
|
14
|
+
class DbService {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.dbInitialized$ = new Observable();
|
|
17
|
+
}
|
|
18
|
+
get Db() {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
putLocal(store, data) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
putLocalRx(store, data) {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
get(store, key) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
getRx(store, key) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
getAll(store, opt) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
getAllRx(store, opt) {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
remove(store, id) {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
removeRx(store, key) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
removeAll(store) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
removeAllRx(store) {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
count(store, opts) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
countRx(store, opts) {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
deleteDb() {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
deleteTable(store) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// @Injectable()
|
|
80
|
+
class DbWebService extends Dexie {
|
|
81
|
+
constructor(config, schemaService) {
|
|
82
|
+
super(config.dbName);
|
|
83
|
+
this.config = config;
|
|
84
|
+
this.schemaService = schemaService;
|
|
85
|
+
this.dbInitialized = new Subject();
|
|
86
|
+
this.dbInitialized$ = this.dbInitialized.asObservable();
|
|
87
|
+
const schema = {};
|
|
88
|
+
schemaService.schema.stores.forEach((s) => {
|
|
89
|
+
let cols = ``;
|
|
90
|
+
for (let c of s.columns) {
|
|
91
|
+
cols += `${c.isPrimaryKey ? `++${c.name}` : `,${c.name}`}`;
|
|
92
|
+
}
|
|
93
|
+
schema[s.name] = cols;
|
|
94
|
+
});
|
|
95
|
+
this.version(1).stores(schema);
|
|
96
|
+
this.open()
|
|
97
|
+
.then((d) => {
|
|
98
|
+
this._db = d;
|
|
99
|
+
this.dbInitialized.next(d);
|
|
100
|
+
})
|
|
101
|
+
.catch((e) => alert(e));
|
|
102
|
+
}
|
|
103
|
+
get Db() {
|
|
104
|
+
return this._db;
|
|
105
|
+
}
|
|
106
|
+
putLocal(store, data) {
|
|
107
|
+
return new Promise(async (resolve, reject) => {
|
|
108
|
+
const schema = this.schemaService.schema.stores.filter((s) => s.name == store)[0];
|
|
109
|
+
const key = schema.columns.filter((s) => s.isPrimaryKey)[0];
|
|
110
|
+
const exist = data[key.name] ? await this.get(store, data[key.name]) : null;
|
|
111
|
+
if (exist) {
|
|
112
|
+
//update
|
|
113
|
+
this.Db
|
|
114
|
+
.table(store)
|
|
115
|
+
.update(data[key.name], data)
|
|
116
|
+
.then((r) => resolve(null), (e) => reject(e));
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.Db
|
|
120
|
+
.table(store)
|
|
121
|
+
.add(data)
|
|
122
|
+
.then((r) => resolve(null), (e) => reject(e));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
putLocalRx(store, data) {
|
|
127
|
+
return new Observable((observer) => {
|
|
128
|
+
this.putLocal(store, data).then((result) => {
|
|
129
|
+
observer.next(result);
|
|
130
|
+
observer.complete();
|
|
131
|
+
}, (e) => observer.error(e));
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
get(store, key) {
|
|
135
|
+
return new Promise((resolve, reject) => {
|
|
136
|
+
if (!this.Db) {
|
|
137
|
+
return reject('Database not initialized. Please wait for dbInitialized$ to emit.');
|
|
138
|
+
}
|
|
139
|
+
this.Db
|
|
140
|
+
.table(store)
|
|
141
|
+
.get(key)
|
|
142
|
+
.then((r) => {
|
|
143
|
+
resolve(r);
|
|
144
|
+
}, (e) => reject(e));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
getRx(store, key) {
|
|
148
|
+
return new Observable((observer) => {
|
|
149
|
+
this.get(store, key).then((value) => {
|
|
150
|
+
observer.next(value);
|
|
151
|
+
observer.complete();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
getByFieldName(storeName, fieldName, key) {
|
|
156
|
+
const filter = {};
|
|
157
|
+
filter[fieldName] = key;
|
|
158
|
+
return this.Db.table(storeName).where(filter).toArray();
|
|
159
|
+
}
|
|
160
|
+
getAll(store, opt) {
|
|
161
|
+
return new Promise(async (resolve, reject) => {
|
|
162
|
+
if (!this.Db) {
|
|
163
|
+
return reject('Database not initialized. Please wait for dbInitialized$ to emit.');
|
|
164
|
+
}
|
|
165
|
+
let table = this.Db.table(store);
|
|
166
|
+
let collection = table.toCollection();
|
|
167
|
+
if (opt?.sortBy) {
|
|
168
|
+
collection = table.orderBy(opt.sortBy);
|
|
169
|
+
}
|
|
170
|
+
if (opt?.sortType && opt?.sortType == 'desc') {
|
|
171
|
+
collection = table.reverse();
|
|
172
|
+
}
|
|
173
|
+
// collection = this.Db.table(store).toCollection();
|
|
174
|
+
if (opt && opt.key && opt.value) {
|
|
175
|
+
if (!opt.keyRange) {
|
|
176
|
+
opt.keyRange = KeyRangeType.equalTo;
|
|
177
|
+
}
|
|
178
|
+
switch (opt.keyRange) {
|
|
179
|
+
case KeyRangeType.startsWithIgnoreCase:
|
|
180
|
+
collection = this.Db
|
|
181
|
+
.table(store)
|
|
182
|
+
.where(opt.key)
|
|
183
|
+
.startsWithIgnoreCase(opt.value);
|
|
184
|
+
break;
|
|
185
|
+
case KeyRangeType.equalTo:
|
|
186
|
+
collection = this.Db
|
|
187
|
+
.table(store)
|
|
188
|
+
.where(opt.key)
|
|
189
|
+
.equals(opt.value);
|
|
190
|
+
break;
|
|
191
|
+
case KeyRangeType.notEqualTo:
|
|
192
|
+
collection = this.Db
|
|
193
|
+
.table(store)
|
|
194
|
+
.where(opt.key)
|
|
195
|
+
.notEqual(opt.value);
|
|
196
|
+
break;
|
|
197
|
+
case KeyRangeType.equalToIgnoreCase:
|
|
198
|
+
collection = this.Db
|
|
199
|
+
.table(store)
|
|
200
|
+
.where(opt.key)
|
|
201
|
+
.equalsIgnoreCase(opt.value);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (opt?.pageIndex != null) {
|
|
206
|
+
collection = collection.offset((opt.pageIndex - 1) * opt.pageSize);
|
|
207
|
+
}
|
|
208
|
+
if (opt?.pageSize != null) {
|
|
209
|
+
collection = collection.limit(opt.pageSize);
|
|
210
|
+
}
|
|
211
|
+
// let data!: T;
|
|
212
|
+
// if(opt?.sortBy) {
|
|
213
|
+
// data = <T>await collection.sortBy(opt.sortBy);
|
|
214
|
+
// } else {
|
|
215
|
+
// data = <T>await collection.toArray();
|
|
216
|
+
// }
|
|
217
|
+
// if(opt.sortType == 'desc') {
|
|
218
|
+
// data = <T>(<any[]>data).reverse();
|
|
219
|
+
// }
|
|
220
|
+
const data = await collection.toArray();
|
|
221
|
+
resolve(data);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
getAllRx(store, opt) {
|
|
225
|
+
return new Observable((observer) => {
|
|
226
|
+
this.getAll(store, opt).then((value) => {
|
|
227
|
+
observer.next(value);
|
|
228
|
+
observer.complete();
|
|
229
|
+
}, (e) => observer.error(e));
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
remove(store, key) {
|
|
233
|
+
return this.Db.table(store).delete(key);
|
|
234
|
+
}
|
|
235
|
+
removeRx(store, key) {
|
|
236
|
+
return new Observable((observer) => {
|
|
237
|
+
this.remove(store, key).then((result) => {
|
|
238
|
+
observer.next(result);
|
|
239
|
+
observer.complete();
|
|
240
|
+
}, (e) => observer.error(e));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
async removeAll(store) {
|
|
244
|
+
const all = await this.getAll(store);
|
|
245
|
+
const schema = this.schemaService.schema.stores.filter((s) => s.name == store)[0];
|
|
246
|
+
const key = schema.columns.filter((s) => s.isPrimaryKey)[0];
|
|
247
|
+
const promises = [];
|
|
248
|
+
for (let r of all) {
|
|
249
|
+
promises.push(this.Db.table(store).delete(key.name));
|
|
250
|
+
}
|
|
251
|
+
await Promise.all(promises);
|
|
252
|
+
}
|
|
253
|
+
removeAllRx(store) {
|
|
254
|
+
return this.getAllRx(store).pipe(switchMap((entries) => {
|
|
255
|
+
const observables = [];
|
|
256
|
+
for (let entry of entries) {
|
|
257
|
+
observables.push(this.removeRx(store, entry.id));
|
|
258
|
+
}
|
|
259
|
+
if (!observables.length) {
|
|
260
|
+
return of(null);
|
|
261
|
+
}
|
|
262
|
+
return forkJoin(observables);
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
count(store, opts) {
|
|
266
|
+
if (opts && opts.key) {
|
|
267
|
+
const pk = this.schemaService.schema.stores
|
|
268
|
+
.filter((s) => s.name == store)[0]
|
|
269
|
+
.columns.filter((s) => s.isPrimaryKey)[0];
|
|
270
|
+
return this.Db.table(store).where(pk.name).equals(opts.key).count();
|
|
271
|
+
}
|
|
272
|
+
return this.Db.table(store).count();
|
|
273
|
+
}
|
|
274
|
+
countRx(store, opts) {
|
|
275
|
+
return new Observable((observer) => {
|
|
276
|
+
this.count(store, opts).then((value) => {
|
|
277
|
+
observer.next(value);
|
|
278
|
+
observer.complete();
|
|
279
|
+
}, (e) => observer.error(e));
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
deleteDb() {
|
|
283
|
+
return new Promise(async (resolve, reject) => {
|
|
284
|
+
await this.Db.delete();
|
|
285
|
+
resolve(null);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
deleteTable(store) {
|
|
289
|
+
return new Observable((observer) => {
|
|
290
|
+
this.Db.table(store).clear().then((result) => {
|
|
291
|
+
observer.next(result);
|
|
292
|
+
observer.complete();
|
|
293
|
+
}, (e) => observer.error(e));
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
var KeyRangeType;
|
|
298
|
+
(function (KeyRangeType) {
|
|
299
|
+
KeyRangeType[KeyRangeType["equalToIgnoreCase"] = 1] = "equalToIgnoreCase";
|
|
300
|
+
KeyRangeType[KeyRangeType["startsWithIgnoreCase"] = 2] = "startsWithIgnoreCase";
|
|
301
|
+
KeyRangeType[KeyRangeType["equalTo"] = 3] = "equalTo";
|
|
302
|
+
KeyRangeType[KeyRangeType["notEqualTo"] = 4] = "notEqualTo";
|
|
303
|
+
})(KeyRangeType || (KeyRangeType = {}));
|
|
304
|
+
|
|
305
|
+
class SchemaService {
|
|
306
|
+
/**
|
|
307
|
+
* Represents a SchemaService that manages the database schema.
|
|
308
|
+
*/
|
|
309
|
+
constructor() {
|
|
310
|
+
this.schema = {
|
|
311
|
+
stores: []
|
|
312
|
+
};
|
|
313
|
+
this.tables = {};
|
|
314
|
+
this._config = {};
|
|
315
|
+
}
|
|
316
|
+
get config() {
|
|
317
|
+
return this._config;
|
|
318
|
+
}
|
|
319
|
+
init(config) {
|
|
320
|
+
this._config = config;
|
|
321
|
+
if (config.schema && config.schema.length) {
|
|
322
|
+
this.schema.stores = this.config.schema;
|
|
323
|
+
this.schema.stores.forEach((s) => this.tables[s.name] = s.name);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: SchemaService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
327
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: SchemaService }); }
|
|
328
|
+
}
|
|
329
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: SchemaService, decorators: [{
|
|
330
|
+
type: Injectable
|
|
331
|
+
}], ctorParameters: () => [] });
|
|
332
|
+
|
|
333
|
+
class DbSettingConstant {
|
|
334
|
+
static { this.SETTING = 'setting'; }
|
|
335
|
+
}
|
|
336
|
+
const DbSettingConfig = {
|
|
337
|
+
schema: {
|
|
338
|
+
name: DbSettingConstant.SETTING,
|
|
339
|
+
columns: [
|
|
340
|
+
{
|
|
341
|
+
name: 'key',
|
|
342
|
+
isPrimaryKey: true,
|
|
343
|
+
type: 'TEXT',
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: 'value',
|
|
347
|
+
type: 'TEXT',
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
class DbSqliteService {
|
|
354
|
+
constructor(config, schemaSvc) {
|
|
355
|
+
this.config = config;
|
|
356
|
+
this.schemaSvc = schemaSvc;
|
|
357
|
+
this._isDbInitialized = false;
|
|
358
|
+
this.dbInitialized = new Subject();
|
|
359
|
+
this.dbInitialized$ = this.dbInitialized.asObservable();
|
|
360
|
+
this._dbName = config.dbName;
|
|
361
|
+
// await this._deleteDatabase();
|
|
362
|
+
// this._db = CapacitorSQLite;
|
|
363
|
+
this._db.open({ database: this._dbName }).then(async (response) => {
|
|
364
|
+
if (response.result) {
|
|
365
|
+
await this._dbSuccess();
|
|
366
|
+
this.initializeDb();
|
|
367
|
+
}
|
|
368
|
+
}, (e) => {
|
|
369
|
+
this._dbError(e);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
getAllRx(store, opt) {
|
|
373
|
+
throw new Error('Method not implemented.');
|
|
374
|
+
}
|
|
375
|
+
testDb() {
|
|
376
|
+
this._db.transaction((tr) => {
|
|
377
|
+
tr.executeSql('SELECT upper(?) AS upperString', ['Test string'], (tr, rs) => {
|
|
378
|
+
console.log('Got upperString result: ' + rs.rows.item(0).upperString);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
initializeDb() {
|
|
383
|
+
const delay = 50;
|
|
384
|
+
//workaround: don't proceed unless db is initialized...wait everytime 50ms
|
|
385
|
+
const _self = this;
|
|
386
|
+
let timerId = setTimeout(async function request() {
|
|
387
|
+
if (!_self._isDbInitialized) {
|
|
388
|
+
//retry
|
|
389
|
+
timerId = setTimeout(request, delay);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
//clear timeout
|
|
393
|
+
clearTimeout(timerId);
|
|
394
|
+
timerId = null;
|
|
395
|
+
await _self._prepareTables();
|
|
396
|
+
// heavy database operations should start from this...
|
|
397
|
+
_self.dbInitialized.next(_self._db);
|
|
398
|
+
}
|
|
399
|
+
}, delay);
|
|
400
|
+
}
|
|
401
|
+
get Db() {
|
|
402
|
+
return this._db;
|
|
403
|
+
}
|
|
404
|
+
putLocal(store, data) {
|
|
405
|
+
return new Promise(async (resolve, reject) => {
|
|
406
|
+
let sql = `BEGIN TRANSACTION;`;
|
|
407
|
+
const values = [];
|
|
408
|
+
const total = await this.count(store);
|
|
409
|
+
if (total) {
|
|
410
|
+
//update
|
|
411
|
+
sql = `UPDATE ${store} SET `;
|
|
412
|
+
//columns
|
|
413
|
+
for (let prop in data) {
|
|
414
|
+
if (data.hasOwnProperty(prop)) {
|
|
415
|
+
sql += `${prop}='${data[prop]}',`;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
//remove extra ',' at the end
|
|
419
|
+
sql = sql.substr(0, sql.length - 1);
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
//insert
|
|
423
|
+
sql = `INSERT INTO ${store} `;
|
|
424
|
+
//columns
|
|
425
|
+
sql += `(`;
|
|
426
|
+
for (let prop in data) {
|
|
427
|
+
if (data.hasOwnProperty(prop)) {
|
|
428
|
+
sql += `${prop},`;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
//remove extra ',' at the end
|
|
432
|
+
sql = sql.substr(0, sql.length - 1);
|
|
433
|
+
sql += `)`;
|
|
434
|
+
//values
|
|
435
|
+
sql += ` VALUES (`;
|
|
436
|
+
for (let prop in data) {
|
|
437
|
+
sql += `?,`;
|
|
438
|
+
values.push(data[prop]);
|
|
439
|
+
}
|
|
440
|
+
sql = sql.substr(0, sql.length - 1);
|
|
441
|
+
sql += `)`;
|
|
442
|
+
}
|
|
443
|
+
sql += `COMMIT TRANSACTION;`;
|
|
444
|
+
const { changes } = await this._db.execute({
|
|
445
|
+
statements: sql,
|
|
446
|
+
values: values,
|
|
447
|
+
});
|
|
448
|
+
resolve(changes);
|
|
449
|
+
// this._db.transaction(async (tx) => {
|
|
450
|
+
// const res = await this._executeSql<{ rowsAffected, insertId }>(tx, sql, values);
|
|
451
|
+
// resolve(res);
|
|
452
|
+
// }, (error) => reject(error));
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
putLocalRx(store, data) {
|
|
456
|
+
return new Observable((observer) => {
|
|
457
|
+
this.putLocal(store, data).then((result) => {
|
|
458
|
+
observer.next(result);
|
|
459
|
+
observer.complete();
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
get(store, key) {
|
|
464
|
+
return new Promise(async (resolve, reject) => {
|
|
465
|
+
//get primary key field form schema
|
|
466
|
+
const table = this.schemaSvc.schema.stores.filter((s) => s.name === store)[0];
|
|
467
|
+
const pk = table.columns.filter((c) => c.isPrimaryKey)[0];
|
|
468
|
+
const pkName = pk.name;
|
|
469
|
+
let sql = `SELECT * FROM ${store} WHERE ${pkName} = '${key}' LIMIT 1`;
|
|
470
|
+
try {
|
|
471
|
+
let data;
|
|
472
|
+
const { values } = await this._db.query({ statement: sql, values: [] });
|
|
473
|
+
if (values.length) {
|
|
474
|
+
data = values[0];
|
|
475
|
+
}
|
|
476
|
+
resolve(data);
|
|
477
|
+
}
|
|
478
|
+
catch (e) {
|
|
479
|
+
reject(e);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
getRx(store, key) {
|
|
484
|
+
// @ts-ignore
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
getAll(store, opt) {
|
|
488
|
+
return new Promise(async (resolve, reject) => {
|
|
489
|
+
let sql = `SELECT * FROM ${store}`;
|
|
490
|
+
try {
|
|
491
|
+
let data;
|
|
492
|
+
const { values } = await this._db.query({ statement: sql, values: [] });
|
|
493
|
+
resolve(values);
|
|
494
|
+
}
|
|
495
|
+
catch (e) {
|
|
496
|
+
reject(e);
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
remove(store, key) {
|
|
501
|
+
return new Promise((resolve, reject) => {
|
|
502
|
+
throw 'remove not impleted in db-sql yet';
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
removeRx(store, key) {
|
|
506
|
+
throw 'remove not impleted in db-sql yet';
|
|
507
|
+
}
|
|
508
|
+
removeAll(store) {
|
|
509
|
+
return new Promise((resolve, reject) => {
|
|
510
|
+
throw 'removeAll not impleted in db-sql yet';
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
removeAllRx(store) {
|
|
514
|
+
throw 'removeAllRx not impleted in db-sql yet';
|
|
515
|
+
}
|
|
516
|
+
count(store, opts) {
|
|
517
|
+
return new Promise(async (resolve, reject) => {
|
|
518
|
+
let sql = `SELECT count(*) AS total FROM ${store} `;
|
|
519
|
+
const { values } = await this._db.query({ statement: sql, values: [] });
|
|
520
|
+
resolve(values);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
countRx(store, opts) {
|
|
524
|
+
return new Observable((observer) => {
|
|
525
|
+
this.count(store, opts).then((result) => {
|
|
526
|
+
observer.next(result);
|
|
527
|
+
observer.complete();
|
|
528
|
+
}, (error) => observer.error(error));
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
deleteDb() {
|
|
532
|
+
return this._deleteDatabase();
|
|
533
|
+
}
|
|
534
|
+
deleteTable(store) {
|
|
535
|
+
throw 'deleteTable not impleted in db-sql yet';
|
|
536
|
+
}
|
|
537
|
+
_prepareTables() {
|
|
538
|
+
return new Promise(async (resolve, reject) => {
|
|
539
|
+
const schemas = this.schemaSvc.schema.stores;
|
|
540
|
+
const promises = [];
|
|
541
|
+
for (let schema of schemas) {
|
|
542
|
+
let sql = `BEGIN TRANSACTION;`;
|
|
543
|
+
sql += `CREATE TABLE IF NOT EXISTS ${schema.name} `;
|
|
544
|
+
sql += `(`;
|
|
545
|
+
for (let col of schema.columns) {
|
|
546
|
+
//TODO: for user table, need to fix primary key
|
|
547
|
+
// const ikPkTypeNumber = col['type'] == 'INTEGER';
|
|
548
|
+
sql += `${col.name}${col.type ? ' ' + col.type : ''}${col['isPrimaryKey'] ? ' PRIMARY KEY' : ''},`;
|
|
549
|
+
}
|
|
550
|
+
//remove extra ',' at the end
|
|
551
|
+
sql = sql.substr(0, sql.length - 1);
|
|
552
|
+
sql += `)`;
|
|
553
|
+
sql += `COMMIT TRANSACTION;`;
|
|
554
|
+
const promise = this._db.execute({ statements: sql });
|
|
555
|
+
promises.push(promise);
|
|
556
|
+
}
|
|
557
|
+
try {
|
|
558
|
+
await Promise.all(promises);
|
|
559
|
+
resolve(null);
|
|
560
|
+
}
|
|
561
|
+
catch (e) {
|
|
562
|
+
reject(e);
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
_deleteDatabase() {
|
|
567
|
+
return this._db.deleteDatabase({ database: this._dbName });
|
|
568
|
+
}
|
|
569
|
+
_dbSuccess() {
|
|
570
|
+
this._isDbInitialized = true;
|
|
571
|
+
}
|
|
572
|
+
_dbError(err) {
|
|
573
|
+
alert('Open database ERROR: ' + JSON.stringify(err));
|
|
574
|
+
}
|
|
575
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DbSqliteService, deps: [{ token: DbServiceConfig }, { token: SchemaService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
576
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DbSqliteService }); }
|
|
577
|
+
}
|
|
578
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DbSqliteService, decorators: [{
|
|
579
|
+
type: Injectable
|
|
580
|
+
}], ctorParameters: () => [{ type: DbServiceConfig }, { type: SchemaService }] });
|
|
581
|
+
|
|
582
|
+
function dbFactory(schemaSvc) {
|
|
583
|
+
const dbConfig = schemaSvc.config;
|
|
584
|
+
switch (dbConfig.dbType) {
|
|
585
|
+
case DbServiceType.IndexDd:
|
|
586
|
+
return new DbWebService(dbConfig, schemaSvc);
|
|
587
|
+
case DbServiceType.Sqlite:
|
|
588
|
+
return new DbSqliteService(dbConfig, schemaSvc);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
const provideDb = () => {
|
|
592
|
+
const providers = [
|
|
593
|
+
SchemaService,
|
|
594
|
+
{
|
|
595
|
+
provide: DbService,
|
|
596
|
+
useFactory: dbFactory,
|
|
597
|
+
deps: [SchemaService],
|
|
598
|
+
}
|
|
599
|
+
];
|
|
600
|
+
return makeEnvironmentProviders(providers);
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Generated bundle index. Do not edit.
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
export { DbService, DbServiceConfig, DbServiceType, DbSettingConfig, DbSettingConstant, DbWebService, KeyRangeType, SchemaService, dbFactory, provideDb };
|
|
608
|
+
//# sourceMappingURL=ngx-universal-zone-database.mjs.map
|