@samet-it/be-db-common 1.1.4 → 1.1.5
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/dist/connection/db.connection.js +8 -1
- package/dist/connection/index.types.d.ts +14 -5
- package/dist/error/db.error.d.ts +1 -2
- package/dist/error/index.d.ts +0 -1
- package/dist/error/index.js +0 -1
- package/dist/repo/db.repo.js +18 -18
- package/package.json +4 -4
- package/dist/error/index.types.d.ts +0 -1
- package/dist/error/index.types.js +0 -2
|
@@ -106,7 +106,8 @@ class DbConnection {
|
|
|
106
106
|
checkError(err, opt) {
|
|
107
107
|
var _a, _b, _c;
|
|
108
108
|
const size = be_base_common_1.errorHandler.addStat(err);
|
|
109
|
-
|
|
109
|
+
const ignoredErrors = (_a = opt === null || opt === void 0 ? void 0 : opt.ignoredErrors) !== null && _a !== void 0 ? _a : [];
|
|
110
|
+
if (ignoredErrors.includes(err) || ignoredErrors.includes(err.name)) {
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
if (opt === null || opt === void 0 ? void 0 : opt.silent) {
|
|
@@ -183,6 +184,9 @@ class DbConnection {
|
|
|
183
184
|
/** {@inheritDoc} */
|
|
184
185
|
exec(fn, p1) {
|
|
185
186
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (!this._props.enabled) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
186
190
|
const opt = this.buildOpt(p1);
|
|
187
191
|
try {
|
|
188
192
|
return yield fn;
|
|
@@ -199,6 +203,9 @@ class DbConnection {
|
|
|
199
203
|
* */
|
|
200
204
|
onModuleInit() {
|
|
201
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
if (!this._props.enabled) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
202
209
|
yield this.connect();
|
|
203
210
|
});
|
|
204
211
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { DbLines } from "../line";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Opt } from "@leyyo/common";
|
|
2
|
+
import type { OmitError, Opt } from "@leyyo/common";
|
|
4
3
|
/**
|
|
5
4
|
* DB query result
|
|
6
5
|
* */
|
|
@@ -16,7 +15,7 @@ export interface DbQueryResult<META> {
|
|
|
16
15
|
/**
|
|
17
16
|
* [when success=false] Couchbase error
|
|
18
17
|
*/
|
|
19
|
-
error?:
|
|
18
|
+
error?: OmitError;
|
|
20
19
|
}
|
|
21
20
|
/**
|
|
22
21
|
* DB query result as a row
|
|
@@ -39,7 +38,7 @@ export interface DbQueryResultMore<E = any, META = unknown> extends DbQueryResul
|
|
|
39
38
|
/**
|
|
40
39
|
* DB query option
|
|
41
40
|
* */
|
|
42
|
-
export interface DbExecOpt {
|
|
41
|
+
export interface DbExecOpt extends Opt {
|
|
43
42
|
/**
|
|
44
43
|
* Name of SQL
|
|
45
44
|
* */
|
|
@@ -48,10 +47,14 @@ export interface DbExecOpt {
|
|
|
48
47
|
* do not use cache
|
|
49
48
|
* */
|
|
50
49
|
noCache?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Ignore context cache
|
|
52
|
+
* */
|
|
53
|
+
ignoreContext?: string;
|
|
51
54
|
/**
|
|
52
55
|
* Ignored errors
|
|
53
56
|
* */
|
|
54
|
-
ignoredErrors?: Array<string>;
|
|
57
|
+
ignoredErrors?: Array<OmitError | string>;
|
|
55
58
|
/**
|
|
56
59
|
* Print sql?
|
|
57
60
|
* */
|
|
@@ -224,6 +227,12 @@ export interface DbMeta {
|
|
|
224
227
|
* DB connection option
|
|
225
228
|
* */
|
|
226
229
|
export interface DbConnOpt {
|
|
230
|
+
/**
|
|
231
|
+
* Is enabled?
|
|
232
|
+
*
|
|
233
|
+
* @type {boolean}
|
|
234
|
+
* */
|
|
235
|
+
enabled?: boolean;
|
|
227
236
|
/**
|
|
228
237
|
* Protocol
|
|
229
238
|
*
|
package/dist/error/db.error.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { SametError } from "@samet-it/be-base-common";
|
|
2
|
-
import type { DbErrorOmit } from "./index.types";
|
|
3
2
|
/**
|
|
4
3
|
* General database error
|
|
5
4
|
* */
|
|
6
|
-
export declare class DbError extends SametError
|
|
5
|
+
export declare class DbError extends SametError {
|
|
7
6
|
}
|
package/dist/error/index.d.ts
CHANGED
package/dist/error/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./index.types"), exports);
|
|
18
17
|
__exportStar(require("./db.error"), exports);
|
|
19
18
|
__exportStar(require("./db-execute.error"), exports);
|
|
20
19
|
__exportStar(require("./db-invalid-value.error"), exports);
|
package/dist/repo/db.repo.js
CHANGED
|
@@ -294,7 +294,7 @@ class DbRepo {
|
|
|
294
294
|
let found;
|
|
295
295
|
if (!opt.noCache && cache.props.isConnected) {
|
|
296
296
|
try {
|
|
297
|
-
found =
|
|
297
|
+
found = yield cache.getByPrimary(key, opt);
|
|
298
298
|
}
|
|
299
299
|
catch (e) {
|
|
300
300
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getByPrimary', 'cache', 'getByPrimary'));
|
|
@@ -305,7 +305,7 @@ class DbRepo {
|
|
|
305
305
|
}
|
|
306
306
|
found = yield this.$getByPrimary(key, opt, true);
|
|
307
307
|
if (!opt.noCache && found && cache.props.isConnected) {
|
|
308
|
-
cache.ingestDoc(found)
|
|
308
|
+
cache.ingestDoc(found, opt)
|
|
309
309
|
.then()
|
|
310
310
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getByPrimary', 'cache', 'ingestDoc')));
|
|
311
311
|
}
|
|
@@ -331,7 +331,7 @@ class DbRepo {
|
|
|
331
331
|
let found;
|
|
332
332
|
if (!opt.noCache && cache.props.isConnected) {
|
|
333
333
|
try {
|
|
334
|
-
found =
|
|
334
|
+
found = yield cache.getBySecondary(key, opt);
|
|
335
335
|
if (found) {
|
|
336
336
|
return found;
|
|
337
337
|
}
|
|
@@ -342,7 +342,7 @@ class DbRepo {
|
|
|
342
342
|
}
|
|
343
343
|
found = yield this.$getBySecondary(key, opt, true);
|
|
344
344
|
if (found && cache.props.isConnected) {
|
|
345
|
-
cache.ingestDoc(found)
|
|
345
|
+
cache.ingestDoc(found, opt)
|
|
346
346
|
.then()
|
|
347
347
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'getBySecondary', 'cache', 'ingestDoc')));
|
|
348
348
|
}
|
|
@@ -378,7 +378,7 @@ class DbRepo {
|
|
|
378
378
|
}
|
|
379
379
|
if (!opt.noCache && cache.props.isConnected) {
|
|
380
380
|
try {
|
|
381
|
-
const found =
|
|
381
|
+
const found = yield cache.getByPrimary(key, opt);
|
|
382
382
|
if (found) {
|
|
383
383
|
return true;
|
|
384
384
|
}
|
|
@@ -408,7 +408,7 @@ class DbRepo {
|
|
|
408
408
|
}
|
|
409
409
|
if (!opt.noCache && cache.props.isConnected) {
|
|
410
410
|
try {
|
|
411
|
-
const found =
|
|
411
|
+
const found = yield cache.getBySecondary(key, opt);
|
|
412
412
|
if (found) {
|
|
413
413
|
return true;
|
|
414
414
|
}
|
|
@@ -439,7 +439,7 @@ class DbRepo {
|
|
|
439
439
|
if (result.urns.length > 0) {
|
|
440
440
|
if (!opt.noCache && cache.props.isConnected) {
|
|
441
441
|
try {
|
|
442
|
-
founds = yield cache.
|
|
442
|
+
founds = yield cache.getByPrimaryMore(result.urns, opt);
|
|
443
443
|
}
|
|
444
444
|
catch (e) {
|
|
445
445
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'getByPrimary'));
|
|
@@ -456,7 +456,7 @@ class DbRepo {
|
|
|
456
456
|
founds = yield this.$listByPrimary(result.urns, opt, true);
|
|
457
457
|
if (founds.length > 0) {
|
|
458
458
|
if (!opt.noCache && cache.props.isConnected) {
|
|
459
|
-
founds.forEach(found => cache.ingestDoc(found)
|
|
459
|
+
founds.forEach(found => cache.ingestDoc(found, opt)
|
|
460
460
|
.then()
|
|
461
461
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'ingestDoc'))));
|
|
462
462
|
}
|
|
@@ -467,7 +467,7 @@ class DbRepo {
|
|
|
467
467
|
if (result.ids.length > 0) {
|
|
468
468
|
if (!opt.noCache && cache.props.isConnected) {
|
|
469
469
|
try {
|
|
470
|
-
founds = yield cache.
|
|
470
|
+
founds = yield cache.getBySecondaryMore(result.ids, opt);
|
|
471
471
|
}
|
|
472
472
|
catch (e) {
|
|
473
473
|
this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'getBySecondary'));
|
|
@@ -484,7 +484,7 @@ class DbRepo {
|
|
|
484
484
|
founds = yield this.$listBySecondary(result.ids, opt, true);
|
|
485
485
|
if (founds.length > 0) {
|
|
486
486
|
if (!opt.noCache && cache.props.isConnected) {
|
|
487
|
-
founds.forEach(found => cache.ingestDoc(found)
|
|
487
|
+
founds.forEach(found => cache.ingestDoc(found, opt)
|
|
488
488
|
.then()
|
|
489
489
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'list', 'cache', 'ingestDoc'))));
|
|
490
490
|
}
|
|
@@ -591,7 +591,7 @@ class DbRepo {
|
|
|
591
591
|
}
|
|
592
592
|
const replacedKey = yield this.$replace(doc, opt, true);
|
|
593
593
|
if (!opt.noCache && cache.props.isConnected) {
|
|
594
|
-
cache.clearDoc(replacedKey)
|
|
594
|
+
cache.clearDoc(replacedKey, opt)
|
|
595
595
|
.then()
|
|
596
596
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'replace', 'cache', 'clearDoc')));
|
|
597
597
|
}
|
|
@@ -630,7 +630,7 @@ class DbRepo {
|
|
|
630
630
|
}
|
|
631
631
|
const createdKey = yield this.$replace(doc, opt, true);
|
|
632
632
|
if (!opt.noCache && cache.props.isConnected) {
|
|
633
|
-
cache.clearDoc(createdKey)
|
|
633
|
+
cache.clearDoc(createdKey, opt)
|
|
634
634
|
.then()
|
|
635
635
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'upsert', 'cache', 'clearDoc')));
|
|
636
636
|
}
|
|
@@ -687,7 +687,7 @@ class DbRepo {
|
|
|
687
687
|
}
|
|
688
688
|
const updatedKey = yield this.$updateByPrimary(key, doc, opt, true);
|
|
689
689
|
if (updatedKey && !opt.noCache && cache.props.isConnected) {
|
|
690
|
-
cache.clearDoc(updatedKey)
|
|
690
|
+
cache.clearDoc(updatedKey, opt)
|
|
691
691
|
.then()
|
|
692
692
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'updateByPrimary', 'cache', 'clearDoc')));
|
|
693
693
|
}
|
|
@@ -731,7 +731,7 @@ class DbRepo {
|
|
|
731
731
|
}
|
|
732
732
|
const updatedKey = yield this.$updateBySecondary(key, doc, opt, true);
|
|
733
733
|
if (updatedKey && !opt.noCache && cache.props.isConnected) {
|
|
734
|
-
cache.clearDoc(updatedKey)
|
|
734
|
+
cache.clearDoc(updatedKey, opt)
|
|
735
735
|
.then()
|
|
736
736
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'updateBySecondary', 'cache', 'clearDoc')));
|
|
737
737
|
}
|
|
@@ -809,7 +809,7 @@ class DbRepo {
|
|
|
809
809
|
}
|
|
810
810
|
const removedKey = yield this.$removeByPrimary(key, opt, true);
|
|
811
811
|
if (removedKey && !opt.noCache && cache.props.isConnected) {
|
|
812
|
-
cache.clearDoc(removedKey)
|
|
812
|
+
cache.clearDoc(removedKey, opt)
|
|
813
813
|
.then()
|
|
814
814
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'removeByPrimary', 'cache', 'clearDoc')));
|
|
815
815
|
}
|
|
@@ -836,7 +836,7 @@ class DbRepo {
|
|
|
836
836
|
}
|
|
837
837
|
const removedKey = yield this.$removeBySecondary(key, opt, true);
|
|
838
838
|
if (removedKey && !opt.noCache && cache.props.isConnected) {
|
|
839
|
-
cache.clearDoc(removedKey)
|
|
839
|
+
cache.clearDoc(removedKey, opt)
|
|
840
840
|
.then()
|
|
841
841
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'removeBySecondary', 'cache', 'clearDoc')));
|
|
842
842
|
}
|
|
@@ -881,7 +881,7 @@ class DbRepo {
|
|
|
881
881
|
}
|
|
882
882
|
const trashedKey = yield this.$trashByPrimary(key, opt, true);
|
|
883
883
|
if (trashedKey && !opt.noCache && cache.props.isConnected) {
|
|
884
|
-
cache.clearDoc(trashedKey)
|
|
884
|
+
cache.clearDoc(trashedKey, opt)
|
|
885
885
|
.then()
|
|
886
886
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'trashByPrimary', 'cache', 'clearDoc')));
|
|
887
887
|
}
|
|
@@ -914,7 +914,7 @@ class DbRepo {
|
|
|
914
914
|
}
|
|
915
915
|
const trashedKey = yield this.$trashBySecondary(key, opt, true);
|
|
916
916
|
if (trashedKey && !opt.noCache && cache.props.isConnected) {
|
|
917
|
-
cache.clearDoc(trashedKey)
|
|
917
|
+
cache.clearDoc(trashedKey, opt)
|
|
918
918
|
.then()
|
|
919
919
|
.catch(e => this.logger.warn(be_base_common_1.errorHandler.common.logText(e, 'trashBySecondary', 'cache', 'clearDoc')));
|
|
920
920
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samet-it/be-db-common",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Backend DB Common",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@leyyo/query": "^1.2.2",
|
|
67
|
-
"@leyyo/common": "^1.2.
|
|
67
|
+
"@leyyo/common": "^1.2.4",
|
|
68
68
|
"@leyyo/type": "^1.1.1",
|
|
69
|
-
"@samet-it/be-base-common": "^1.1.
|
|
70
|
-
"@samet-it/be-cache-common": "^1.1.
|
|
69
|
+
"@samet-it/be-base-common": "^1.1.4",
|
|
70
|
+
"@samet-it/be-cache-common": "^1.1.6"
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type DbErrorOmit = Omit<Error, 'message' | 'name' | 'stack'>;
|