@samet-it/be-db-common 1.1.5 → 1.1.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,25 +1,26 @@
1
- import type { Entity, IdDocLike, Pair, UrnDocLike, UrnTuple } from "@samet-it/be-base-common";
2
- import type { DbConnectionBase, DbExecOpt } from "../connection";
3
- import type { DefDims, Portion, View } from "@samet-it/be-base-common";
1
+ import type { DefDims, Entity, IdDocLike, Pair, Portion, UrnDef, UrnDocLike, UrnTuple, View } from "@samet-it/be-base-common";
2
+ import type { DbConnectionLike, UserFetcherLambda } from "../connection";
4
3
  import type { QueryAny, QueryRegular } from "@leyyo/query";
5
- import type { CacheConnectionLike, CacheChannelLike } from "@samet-it/be-cache-common";
6
- import type { KeyValue, StrKey } from "@leyyo/common";
4
+ import type { CacheChannelLike, CacheConnectionLike, CacheExecOpt } from "@samet-it/be-cache-common";
5
+ import type { KeyValue, OmitError, Opt, StrKey } from "@leyyo/common";
6
+ import type { DbLines } from "../line";
7
7
  /**
8
8
  * DB repository interface
9
9
  *
10
10
  * Generics:
11
- * - 0-`CONN`: db connection {@link DbConnectionBase}
11
+ * - 0-`CONN`: db connection {@link DbConnectionLike}
12
12
  * - 1-`OPT`: db execution options {@link DbExecOpt}
13
- * - 2-`ENT`: entity {@link Entity}
14
- * - 3-`ID`: id type {@link KeyValue}
15
- * - 4-`URN`: urn interface {@link UrnDocLike}
16
- * - 5-`VIEW`: view interface for presentation layer {@link View}
17
- * - 6-`PAIR`: pair interface for presentation layer {@link Pair}
18
- * - 7-`PORTION`: portion interface for presentation layer {@link Portion}
19
- * - 8-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
20
- * - 9-`DIMS`: dimensions for presentation layer {@link DefDims}
13
+ * - 2-`META`: query result metadata {@link DbMeta}
14
+ * - 3-`ENT`: entity {@link Entity}
15
+ * - 4-`ID`: id type {@link KeyValue}
16
+ * - 5-`URN`: urn interface {@link UrnDocLike}
17
+ * - 6-`VIEW`: view interface for presentation layer {@link View}
18
+ * - 7-`PAIR`: pair interface for presentation layer {@link Pair}
19
+ * - 8-`PORTION`: portion interface for presentation layer {@link Portion}
20
+ * - 9-`KEYS`: keys to autocomplete, def: keys of {@link Entity}
21
+ * - 10-`DIMS`: dimensions for presentation layer {@link DefDims}
21
22
  * */
22
- export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt, ENT extends Entity<ID>, ID extends KeyValue, URN extends UrnDocLike, VIEW extends View<ID>, PAIR extends Pair<ID>, PORTION extends Portion<ID>, KEYS extends string, DIMS extends DefDims> {
23
+ export interface DbRepoLike<CONN extends DbConnectionLike, OPT extends DbExecOpt, META extends DbMeta, ENT extends Entity<ID>, ID extends KeyValue, URN extends UrnDocLike, VIEW extends View<ID>, PAIR extends Pair<ID>, PORTION extends Portion<ID>, KEYS extends string, DIMS extends DefDims> {
23
24
  /**
24
25
  * Props on repository
25
26
  * */
@@ -28,6 +29,215 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
28
29
  * Casts current instance to given type
29
30
  * */
30
31
  $cast<T>(): T;
32
+ /**
33
+ * Shortcut to {@link DbConnOpt#isEnabled}
34
+ * */
35
+ get isEnabled(): boolean;
36
+ /**
37
+ * Shortcut to {@link DbConnOpt#userFetcher}
38
+ * */
39
+ get userFetcher(): UserFetcherLambda;
40
+ /**
41
+ * Shortcut to {@link DbConnProps#conn}
42
+ * */
43
+ get conn(): CONN;
44
+ /**
45
+ * Shortcut to {@link DbConnProps#isConnected}
46
+ * */
47
+ get isConnected(): boolean;
48
+ /**
49
+ * Shortcut to {@link DbRepoOpt#cache}
50
+ * */
51
+ get cache(): CacheChannelLike<CacheConnectionLike, CacheExecOpt, ENT, ID>;
52
+ /**
53
+ * Shortcut to {@link DbRepoOpt#version}
54
+ * */
55
+ get modelVersion(): number;
56
+ /**
57
+ * Shortcut to {@link DbRepoOpt#urnDelimiter}
58
+ * */
59
+ get urnDelimiter(): UrnDelimiter;
60
+ /**
61
+ * Shortcut to {@link DbRepoOpt#urnPrefix}
62
+ * */
63
+ get urnPrefix(): string;
64
+ /**
65
+ * Shortcut to {@link DbRepoOpt#useNumericId}
66
+ * */
67
+ get hasNumericId(): boolean;
68
+ /**
69
+ * Shortcut to {@link DbRepoOpt#useIsoDate}
70
+ * */
71
+ get hasIsoDate(): boolean;
72
+ /**
73
+ * Shortcut to {@link DbRepoOpt#idSame}
74
+ * */
75
+ get isIdSame(): boolean;
76
+ /**
77
+ * Shortcut to {@link DbRepoOpt#useSoftDelete}
78
+ * */
79
+ get hasSoftDelete(): boolean;
80
+ /**
81
+ * Shortcut to {@link DbRepoOpt#useCreatedAt}
82
+ * */
83
+ get hasCreatedAt(): boolean;
84
+ /**
85
+ * Shortcut to {@link DbRepoOpt#useCreatedBy}
86
+ * */
87
+ get hasCreatedBy(): boolean;
88
+ /**
89
+ * Shortcut to {@link DbRepoOpt#useUpdatedAt}
90
+ * */
91
+ get hasUpdatedAt(): boolean;
92
+ /**
93
+ * Shortcut to {@link DbRepoOpt#useUpdatedBy}
94
+ * */
95
+ get hasUpdatedBy(): boolean;
96
+ /**
97
+ * Shortcut to {@link DbRepoOpt#useVersion}
98
+ * */
99
+ get hasVersion(): boolean;
100
+ /**
101
+ * Shortcut to {@link DbRepoOpt#useRevision}
102
+ * */
103
+ get hasRevision(): boolean;
104
+ /**
105
+ * Shortcut to {@link DbRepoOpt#noInsert}
106
+ * */
107
+ get isNoInsert(): boolean;
108
+ /**
109
+ * Shortcut to {@link DbRepoOpt#noUpdate}
110
+ * */
111
+ get isNoUpdate(): boolean;
112
+ /**
113
+ * Shortcut to {@link DbRepoOpt#noTrash}
114
+ * */
115
+ get isNoTrash(): boolean;
116
+ /**
117
+ * Shortcut to {@link DbRepoOpt#noRemove}
118
+ * */
119
+ get isNoRemove(): boolean;
120
+ /**
121
+ * Shortcut to {@link DbRepoOpt#alphaFn}
122
+ * */
123
+ get alphaFn(): DbRepoExtensionLambda<ENT, ID>;
124
+ /**
125
+ * Shortcut to {@link DbRepoOpt#searchFn}
126
+ * */
127
+ get searchFn(): DbRepoExtensionLambda<ENT, ID>;
128
+ /**
129
+ * Shortcut to {@link DbRepoOpt#irregularFn}
130
+ * */
131
+ get irregularFn(): DbRepoExtensionLambda<ENT, ID>;
132
+ /**
133
+ * Shortcut to {@link DbRepoOpt#forbiddenSet}
134
+ * */
135
+ get forbiddenSet(): Array<keyof ENT>;
136
+ /**
137
+ * Shortcut to {@link DbConnProps#path}
138
+ * */
139
+ get path(): string;
140
+ /**
141
+ * Shortcut to {@link DbConnProps#table}
142
+ * */
143
+ get table(): string;
144
+ /**
145
+ * Shortcut to {@link DbConnProps#urnLength}
146
+ * */
147
+ get urnLength(): number;
148
+ /**
149
+ * Check error
150
+ *
151
+ * @param {Error} err - error
152
+ * @param {DbExecOpt} opt - option
153
+ * */
154
+ checkError(err: Error, opt: OPT | Opt): void;
155
+ /**
156
+ * Field name
157
+ *
158
+ * @param {string} field - raw field name
159
+ * @return {string} - formatted field name
160
+ * */
161
+ field(field: string): string;
162
+ /**
163
+ * Field name
164
+ * @alias #field
165
+ *
166
+ * @param {string} field - raw field name
167
+ * @return {string} - formatted field name
168
+ * */
169
+ f(field: string): string;
170
+ /**
171
+ * Format value
172
+ *
173
+ * @param {string} value - raw value
174
+ * @return {string} - formatted value
175
+ * */
176
+ value(value: unknown): string;
177
+ /**
178
+ * Format value
179
+ * @alias #value
180
+ *
181
+ * @param {string} value - raw value
182
+ * @return {string} - formatted value
183
+ * */
184
+ v(value: unknown): string;
185
+ /**
186
+ * Check rows and discard trashed
187
+ *
188
+ * @param {Array<any>} rows - rows
189
+ * @return {Array<any>} - checked rows
190
+ * */
191
+ rows<T>(rows: Array<T>): Array<T>;
192
+ /**
193
+ * Check row and discard trashed
194
+ *
195
+ * @param {any} row - row
196
+ * @return {any} - checked row
197
+ * */
198
+ row<T>(row: T): T | undefined;
199
+ /**
200
+ * Return first row of rows
201
+ *
202
+ * @param {Array<any>} rows - rows
203
+ * @return {any} - first row if exists
204
+ * */
205
+ first<T>(rows: Array<T>): T | undefined;
206
+ /**
207
+ * Build option
208
+ *
209
+ * @param {(DbExecOpt|string)?} opt - option or query name
210
+ * @param {string?} name - query name, if first param is option
211
+ * @return {DbExecOpt} - formatted option
212
+ * */
213
+ buildOpt(opt?: Partial<OPT> | string, name?: string): OPT;
214
+ /**
215
+ * Execute a lambda
216
+ *
217
+ * @param {function} fn - promise callback
218
+ * @param {(DbExecOpt|string)?} opt - option or query name
219
+ * @return {Promise} - generic type
220
+ * @async
221
+ * */
222
+ exec<T>(fn: Promise<T>, opt?: string | Omit<OPT, 'printSql'>): Promise<T>;
223
+ /**
224
+ * Execute a sql and return rows
225
+ *
226
+ * @param {(string|DbLines)} sql - sql or sql lines
227
+ * @param {(DbExecOpt|string)?} opt - option or query name
228
+ * @return {Promise<DbQueryResultMore>} - rows
229
+ * @async
230
+ * */
231
+ more<T>(sql: string | DbLines, opt?: string | OPT): Promise<DbQueryResultMore<T, META>>;
232
+ /**
233
+ * Execute a sql and return a row
234
+ *
235
+ * @param {(string|DbLines)} sql - sql or sql lines
236
+ * @param {(DbExecOpt|string)?} opt - option or query name
237
+ * @return {Promise<DbQueryResultOne>} - row
238
+ * @async
239
+ * */
240
+ one<T>(sql: string | DbLines, opt?: string | OPT): Promise<DbQueryResultOne<T, META>>;
31
241
  /**
32
242
  * Build urn with prefix from urn object
33
243
  *
@@ -45,12 +255,12 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
45
255
  /**
46
256
  * Get document by key (primary or secondary)
47
257
  *
48
- * @param {KeyValue} key - primary or secondary key
258
+ * @param {Portion|KeyValue} key - primary or secondary key
49
259
  * @param {(opt?: OPT|string)?} opt - option or query name
50
260
  * @return {Promise<Entity?>} - document
51
261
  * @async
52
262
  * */
53
- get(key: KeyValue, opt?: OPT | string): Promise<ENT | undefined>;
263
+ get(key: PORTION | KeyValue, opt?: OPT | string): Promise<ENT | undefined>;
54
264
  /**
55
265
  * Get document by primary key
56
266
  *
@@ -94,12 +304,12 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
94
304
  /**
95
305
  * Document exists by key (primary or secondary)
96
306
  *
97
- * @param {KeyValue} key - primary or secondary key
307
+ * @param {Portion|KeyValue} key - primary or secondary key
98
308
  * @param {(opt?: OPT|string)?} opt - option or query name
99
309
  * @return {Promise<boolean>} - exists or not
100
310
  * @async
101
311
  * */
102
- exists(key: KeyValue, opt?: OPT | string): Promise<boolean>;
312
+ exists(key: PORTION | KeyValue, opt?: OPT | string): Promise<boolean>;
103
313
  /**
104
314
  * Document exists by primary key
105
315
  *
@@ -143,13 +353,13 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
143
353
  /**
144
354
  * List documents by keys (primary or secondary)
145
355
  *
146
- * @param {Array<KeyValue>} keys - primary or secondary keys
356
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
147
357
  * @param {(opt?: OPT|string)?} opt - option or query name
148
358
  * @param {boolean?} ignoreCheck - ignores to check input
149
359
  * @return {Promise<Array<Entity>>} - documents
150
360
  * @async
151
361
  * */
152
- list(keys: Array<KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
362
+ list(keys: Array<PORTION | KeyValue>, opt?: OPT | string, ignoreCheck?: boolean): Promise<Array<ENT>>;
153
363
  /**
154
364
  * List documents by primary keys
155
365
  *
@@ -254,14 +464,14 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
254
464
  /**
255
465
  * Update document by key (primary or secondary)
256
466
  *
257
- * @param {KeyValue} key - primary or secondary key
467
+ * @param {Portion|KeyValue} key - primary or secondary key
258
468
  * @param {Entity} doc - document
259
469
  * @param {(opt?: OPT|string)?} opt - option or query name
260
470
  * @param {boolean?} ignoreCheck - ignores to check input
261
471
  * @return {Promise<string>}
262
472
  * @async
263
473
  * */
264
- update(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
474
+ update(key: PORTION | KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
265
475
  /**
266
476
  * Update document by primary key
267
477
  *
@@ -309,33 +519,33 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
309
519
  /**
310
520
  * Set document with partial data by key (primary or secondary)
311
521
  *
312
- * @param {KeyValue} key - primary or secondary key
522
+ * @param {Portion|KeyValue} key - primary or secondary key
313
523
  * @param {Partial<Entity>} doc - partial entity will be set
314
524
  * @param {(opt?: OPT|string)?} opt - option or query name
315
525
  * @param {boolean?} ignoreCheck - ignores to check input
316
526
  * @return {Promise<string>}
317
527
  * @async
318
528
  * */
319
- set(key: KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
529
+ set(key: PORTION | KeyValue, doc: Partial<ENT>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
320
530
  /**
321
531
  * Unset document for given fields
322
532
  *
323
- * @param {KeyValue} key - primary or secondary key
533
+ * @param {Portion|KeyValue} key - primary or secondary key
324
534
  * @param {Array<string>} fields - fields will be unset
325
535
  * @param {(opt?: OPT|string)?} opt - option or query name
326
536
  * @param {boolean?} ignoreCheck - ignores to check input
327
537
  * @return {Promise<string>}
328
538
  * @async
329
539
  * */
330
- unset(key: KeyValue, fields: Array<keyof ENT | KEYS | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
540
+ unset(key: PORTION | KeyValue, fields: Array<keyof ENT | KEYS | string>, opt?: OPT | string, ignoreCheck?: boolean): Promise<string>;
331
541
  /**
332
542
  * Remove document (hard delete) by key (primary or secondary)
333
543
  *
334
- * @param {KeyValue} key - primary or secondary key
544
+ * @param {Portion|KeyValue} key - primary or secondary key
335
545
  * @param {(opt?: OPT|string)?} opt - option or query name
336
546
  * @async
337
547
  * */
338
- remove(key: KeyValue, opt?: OPT | string): Promise<string>;
548
+ remove(key: PORTION | KeyValue, opt?: OPT | string): Promise<string>;
339
549
  /**
340
550
  * Remove document by primary key (hard delete)
341
551
  *
@@ -375,11 +585,11 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
375
585
  /**
376
586
  * Trash document (soft delete) by key (primary or secondary)
377
587
  *
378
- * @param {KeyValue} key - primary or secondary key
588
+ * @param {Portion|KeyValue} key - primary or secondary key
379
589
  * @param {(opt?: OPT|string)?} opt - option or query name
380
590
  * @async
381
591
  * */
382
- trash(key: KeyValue, opt?: OPT | string): Promise<string>;
592
+ trash(key: PORTION | KeyValue, opt?: OPT | string): Promise<string>;
383
593
  /**
384
594
  * Trash document by primary key (soft delete)
385
595
  *
@@ -434,64 +644,48 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
434
644
  * Generics
435
645
  * - 0-`R`: dim interface {@link IdDocLike}
436
646
  *
437
- * @param {KeyValue} key - primary or secondary key
647
+ * @param {Portion|KeyValue} key - primary or secondary key
438
648
  * @param {string?} dim - dimension, default: `def`
439
649
  * @return {Promise<IdDocLike>} - dim object
440
650
  * @async
441
651
  * */
442
- getDim<R extends IdDocLike<ID>>(key: KeyValue, dim?: DIMS): Promise<R>;
652
+ getDim<R extends IdDocLike<ID>>(key: PORTION | KeyValue, dim?: DIMS): Promise<R>;
443
653
  /**
444
654
  * List dims by keys (primary or secondary)
445
655
  *
446
656
  * Generics
447
657
  * - 0-`R`: dim interface {@link IdDocLike}
448
658
  *
449
- * @param {Array<string>} keys - primary or secondary keys
659
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
450
660
  * @param {string?} dim - dimension, default: `def`
451
661
  * @param {boolean?} ignoreCheck - ignores to check input
452
662
  * @return {Promise<Array<IdDocLike>>} - dim objects
453
663
  * */
454
- listDims<R extends IdDocLike<ID>>(keys: Array<KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
455
- /**
456
- * Set pair by document
457
- *
458
- * @param {Entity} doc - document
459
- * @return {Promise<Pair>} - pair object
460
- * @async
461
- * */
462
- $toPair(doc: ENT): Promise<PAIR>;
664
+ listDims<R extends IdDocLike<ID>>(keys: Array<PORTION | KeyValue>, dim?: DIMS, ignoreCheck?: boolean): Promise<Array<R>>;
463
665
  /**
464
666
  * Get pair by key (primary or secondary)
465
667
  *
466
- * @param {KeyValue} key - primary or secondary key
668
+ * @param {Portion|KeyValue} key - primary or secondary key
467
669
  * @return {Promise<Pair>} - pair object
468
670
  * @async
469
671
  * */
470
- getPair(key: KeyValue): Promise<PAIR>;
672
+ getPair(key: PORTION | KeyValue): Promise<PAIR>;
471
673
  /**
472
674
  * List pairs by keys (primary or secondary)
473
675
  *
474
- * @param {Array<KeyValue>} keys - primary or secondary keys
676
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
475
677
  * @param {boolean?} ignoreCheck - ignores to check input
476
678
  * @return {Promise<Array<Pair>>} - pair objects
477
679
  * */
478
- listPairs(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
479
- /**
480
- * Set view by document
481
- *
482
- * @param {Entity} doc - document
483
- * @return {Promise<View>} - view object
484
- * @async
485
- * */
486
- $toView(doc: ENT): Promise<VIEW>;
680
+ listPairs(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PAIR>>;
487
681
  /**
488
682
  * Get view by key (primary or secondary)
489
683
  *
490
- * @param {KeyValue} key - primary or secondary key
684
+ * @param {Portion|KeyValue} key - primary or secondary key
491
685
  * @return {Promise<View>} - view object
492
686
  * @async
493
687
  * */
494
- getView(key: KeyValue): Promise<VIEW>;
688
+ getView(key: PORTION | KeyValue): Promise<VIEW>;
495
689
  /**
496
690
  * List views by keys (primary or secondary)
497
691
  *
@@ -500,30 +694,22 @@ export interface DbRepoLike<CONN extends DbConnectionBase, OPT extends DbExecOpt
500
694
  * @return {Promise<Array<View>>} - view objects
501
695
  * */
502
696
  listViews(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<VIEW>>;
503
- /**
504
- * Set portion by document
505
- *
506
- * @param {Entity} doc - document
507
- * @return {Promise<Portion>} - portion object
508
- * @async
509
- * */
510
- $toPortion(doc: ENT): Promise<PORTION>;
511
697
  /**
512
698
  * Get portion by key (primary or secondary)
513
699
  *
514
- * @param {KeyValue} key - primary or secondary key
700
+ * @param {Portion|KeyValue} key - primary or secondary key
515
701
  * @return {Promise<Portion>} - portion object
516
702
  * @async
517
703
  * */
518
- getPortion(key: KeyValue): Promise<PORTION>;
704
+ getPortion(key: PORTION | KeyValue): Promise<PORTION>;
519
705
  /**
520
706
  * List portions by key (primary or secondary)
521
707
  *
522
- * @param {Array<KeyValue>} keys - primary or secondary keys
708
+ * @param {Array<Portion|KeyValue>} keys - primary or secondary keys
523
709
  * @param {boolean?} ignoreCheck - ignores to check input
524
710
  * @return {Promise<Array<Portion>>} - portion objects
525
711
  * */
526
- listPortions(keys: Array<KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
712
+ listPortions(keys: Array<PORTION | KeyValue>, ignoreCheck?: boolean): Promise<Array<PORTION>>;
527
713
  }
528
714
  /**
529
715
  * DB repository option
@@ -538,7 +724,7 @@ export interface DbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue> {
538
724
  *
539
725
  * @type {CacheChannelLike}
540
726
  * */
541
- cache?: CacheChannelLike<CacheConnectionLike, ENT, ID>;
727
+ cache?: CacheChannelLike<CacheConnectionLike, CacheExecOpt, ENT, ID>;
542
728
  /**
543
729
  * Model version
544
730
  *
@@ -583,7 +769,7 @@ export interface DbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue> {
583
769
  * - if yes, id is same with urn
584
770
  * - if no, id is not same with urn
585
771
  *
586
- * @fields `_urn`, `id`
772
+ * @fields `urn`, `id`
587
773
  * @default false
588
774
  * */
589
775
  idSame?: boolean;
@@ -733,26 +919,21 @@ export interface DbRepoOpt<ENT extends Entity<ID>, ID extends KeyValue> {
733
919
  * @type {Array<string>}
734
920
  * */
735
921
  forbiddenSet?: Array<keyof ENT>;
736
- /**
737
- * Field list which can not be unset (clear,delete)
738
- *
739
- * @type {Array<string>}
740
- * */
741
- forbiddenUnset?: Array<keyof ENT>;
742
922
  }
743
923
  /**
744
924
  * DB repository props
745
925
  *
746
926
  * Generics:
747
- * - 0-`CONN`: db connection {@link DbConnectionBase}
748
- * - 1-`ENT`: entity {@link Entity}
749
- * - 2-`ID`: id type {@link KeyValue}
927
+ * - 0-`CONN`: db connection {@link DbConnectionLike}
928
+ * - 1-`OPT`: db execution options {@link DbExecOpt}
929
+ * - 2-`ENT`: entity {@link Entity}
930
+ * - 3-`ID`: id type {@link KeyValue}
750
931
  * */
751
- export interface DbRepoProps<CONN extends DbConnectionBase, ENT extends Entity<ID>, ID extends KeyValue> extends DbRepoOpt<ENT, ID> {
932
+ export interface DbRepoProps<CONN extends DbConnectionLike, ENT extends Entity<ID>, ID extends KeyValue> extends DbRepoOpt<ENT, ID> {
752
933
  /**
753
934
  * DB connection
754
935
  *
755
- * @type {DbConnectionBase}
936
+ * @type {DbConnectionLike}
756
937
  * */
757
938
  conn: CONN;
758
939
  /**
@@ -762,17 +943,17 @@ export interface DbRepoProps<CONN extends DbConnectionBase, ENT extends Entity<I
762
943
  * */
763
944
  path: string;
764
945
  /**
765
- * Length of urn prefix
946
+ * Table path, generally it will be "{db}"."{schema}"."{table}"
766
947
  *
767
- * @type {number}
948
+ * @type {string}
768
949
  * */
769
- urnLength?: number;
950
+ table: string;
770
951
  /**
771
- * Is connected
952
+ * Length of urn prefix
772
953
  *
773
- * @type {boolean}
954
+ * @type {number}
774
955
  * */
775
- isConnected?: boolean;
956
+ urnLength?: number;
776
957
  }
777
958
  /**
778
959
  * DB keys result
@@ -790,16 +971,16 @@ export interface DbCheckKeysResult<ID extends KeyValue> {
790
971
  *
791
972
  * Tuple
792
973
  * - 0: urn or id value
793
- * - 1: field name as _urn or id
974
+ * - 1: field name as urn or id
794
975
  *
795
976
  * Generics:
796
977
  * - 0-`ID`: id type {@link KeyValue}
797
978
  *
798
979
  * Options
799
- * - if primary(urn) => `[value (string), '_urn'];
980
+ * - if primary(urn) => `[value (string), 'urn'];
800
981
  * - if secondary(id) => `[value (string|number), 'id'];
801
982
  * */
802
- export type DbCheckKeysTuple<ID extends KeyValue> = [string, '_urn'] | [ID, 'id'];
983
+ export type DbCheckKeysTuple<ID extends KeyValue> = [string, 'urn'] | [ID, 'id'];
803
984
  /**
804
985
  * DB `$toUrnTuple` lambda
805
986
  *
@@ -831,25 +1012,22 @@ export type DbRepoToUrnTuple<URN extends UrnDocLike = UrnDocLike> = (urnRec: URN
831
1012
  export type DbRepoToDim<R, ENT extends Entity<ID>, ID extends KeyValue, DIMS extends DefDims = DefDims> = (doc: ENT, dim: DIMS | undefined) => Promise<R>;
832
1013
  /**
833
1014
  * Default model which contains keys
1015
+ *
1016
+ * Generics:
1017
+ * - 0-`ID`: id type {@link KeyValue}
834
1018
  * */
835
- export interface DbIdLike {
1019
+ export interface DbIdLike<ID extends KeyValue = KeyValue> {
836
1020
  /**
837
1021
  * Secondary key for an entity
838
1022
  *
839
1023
  * @type {KeyValue}
840
1024
  */
841
- id?: KeyValue;
1025
+ id?: ID;
842
1026
  /**
843
1027
  * Primary key for an entity
844
1028
  *
845
1029
  * @type {string}
846
1030
  */
847
- _urn?: string;
848
- /**
849
- * Alternative usage for {@link #_urn}
850
- *
851
- * @type {string}
852
- */
853
1031
  urn?: string;
854
1032
  }
855
1033
  /**
@@ -867,3 +1045,115 @@ export type DbRepoExtensionLambda<ENT extends Entity<ID>, ID extends KeyValue> =
867
1045
  * Urn delimiter literals (options)
868
1046
  * */
869
1047
  export type UrnDelimiter = ',' | '|' | ';' | '/';
1048
+ /**
1049
+ * DB meta
1050
+ * */
1051
+ export interface DbMeta {
1052
+ }
1053
+ /**
1054
+ * DB query option
1055
+ * */
1056
+ export interface DbExecOpt extends Opt {
1057
+ /**
1058
+ * Name of SQL
1059
+ * */
1060
+ name?: string;
1061
+ /**
1062
+ * do not use cache
1063
+ * */
1064
+ noCache?: boolean;
1065
+ /**
1066
+ * Ignore context cache
1067
+ * */
1068
+ ignoreContext?: string;
1069
+ /**
1070
+ * Ignored errors
1071
+ * */
1072
+ ignoredErrors?: Array<OmitError | string>;
1073
+ /**
1074
+ * Print sql?
1075
+ * */
1076
+ printSql?: boolean;
1077
+ /**
1078
+ * Ignore any error
1079
+ * */
1080
+ silent?: boolean;
1081
+ /**
1082
+ * Trash id for only trash case
1083
+ * */
1084
+ trashId?: string;
1085
+ }
1086
+ /**
1087
+ * DB query result as a row
1088
+ *
1089
+ * Generics:
1090
+ * - 0-`E`: result model, it will be row type
1091
+ * - 1-`META`: query result metadata {@link DbMeta}
1092
+ * */
1093
+ export interface DbQueryResultOne<E = any, META extends DbMeta = DbMeta> extends DbQueryResult<META> {
1094
+ /**
1095
+ * The rows which have been returned by the query.
1096
+ */
1097
+ row: E | undefined;
1098
+ }
1099
+ /**
1100
+ * DB query result as rows
1101
+ *
1102
+ * Generics:
1103
+ * - 0-`E`: result model, it will be rows item type, `rows: E[]`
1104
+ * - 1-`META`: query result metadata {@link DbMeta}
1105
+ * */
1106
+ export interface DbQueryResultMore<E = any, META extends DbMeta = DbMeta> extends DbQueryResult<META> {
1107
+ /**
1108
+ * The rows which have been returned by the query.
1109
+ */
1110
+ rows: E[];
1111
+ }
1112
+ /**
1113
+ * DB query result
1114
+ *
1115
+ * Generics:
1116
+ * - 0-`META`: query result metadata {@link DbMeta}
1117
+ * */
1118
+ export interface DbQueryResult<META> {
1119
+ /**
1120
+ * Success or failure
1121
+ */
1122
+ success: boolean;
1123
+ /**
1124
+ * [when success=true] The meta-data which has been returned by the query.
1125
+ */
1126
+ meta?: META;
1127
+ /**
1128
+ * [when success=false] Couchbase error
1129
+ */
1130
+ error?: OmitError;
1131
+ }
1132
+ /**
1133
+ * Couchbase direct repository (collection) option
1134
+ *
1135
+ * Generics:
1136
+ * - 0-`ENT`: entity {@link Entity}
1137
+ * - 1-`ID`: id type {@link KeyValue}
1138
+ * - 2-`URN`: urn interface {@link UrnDocLike}
1139
+ * - 3-`DIMS`: dimensions for presentation layer {@link DefDims}
1140
+ * - 4-`R`: ??
1141
+ * */
1142
+ export interface DbRepoDirectOpt<ENT extends Entity<ID>, ID extends KeyValue = KeyValue, URN extends UrnDocLike = UrnDef<ID>, DIMS extends DefDims = DefDims, R = unknown> extends DbRepoOpt<ENT, ID> {
1143
+ /**
1144
+ * Name of logger class
1145
+ * */
1146
+ name?: string;
1147
+ /**
1148
+ * Overridable method to easy use
1149
+ * */
1150
+ $toUrnTuple?: DbRepoToUrnTuple<URN>;
1151
+ /**
1152
+ * Overridable method to easy use
1153
+ * */
1154
+ $toDim?: DbRepoToDim<R, ENT, ID, DIMS>;
1155
+ /**
1156
+ * Indexed fields
1157
+ * */
1158
+ $indexedFields?: Array<keyof ENT | string>;
1159
+ }