Skip to content

Commit cd598d2

Browse files
authored
Merge pull request #249 from JS-AK/feat/pg-core/model
feat: updated pg-core domain methods
2 parents ed54480 + eb2bc3e commit cd598d2

File tree

32 files changed

+669
-300
lines changed

32 files changed

+669
-300
lines changed

src/lib/mysql/domain/domain.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class BaseDomain<TC extends {
7575

7676
async getArrByParams<T extends keyof TC["TableFields"]>(options: {
7777
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
78-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
78+
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
7979
selected?: [T, ...T[]];
8080
pagination?: SharedTypes.TPagination;
8181
order?: {
@@ -93,7 +93,7 @@ export class BaseDomain<TC extends {
9393

9494
async getCountByParams(options: {
9595
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
96-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
96+
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
9797
}): Promise<number> {
9898
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
9999
}
@@ -103,7 +103,7 @@ export class BaseDomain<TC extends {
103103
*/
104104
async getGuaranteedOneByParams<T extends keyof TC["TableFields"]>(options: {
105105
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
106-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
106+
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
107107
selected?: [T, ...T[]];
108108
}): Promise<Pick<TC["TableFields"], T>> {
109109
return this.model.getOneByParams(
@@ -114,7 +114,7 @@ export class BaseDomain<TC extends {
114114

115115
async getOneByParams<T extends keyof TC["TableFields"]>(options: {
116116
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
117-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
117+
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
118118
selected?: [T, ...T[]];
119119
}): Promise<{ message?: string; one?: Pick<TC["TableFields"], T>; }> {
120120
const one = await this.model.getOneByParams(

src/lib/pg/domain/domain.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class BaseDomain<TC extends {
127127
*/
128128
deleteByParams: (options: {
129129
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
130-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
130+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
131131
}): Types.TCompareQueryResult => this.model.compareQuery.deleteByParams({ $and: options.params, $or: options.paramsOr }),
132132

133133
/**
@@ -153,7 +153,7 @@ export class BaseDomain<TC extends {
153153
*/
154154
getArrByParams: <T extends keyof TC["TableFields"]>(options: {
155155
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
156-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
156+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
157157
selected?: [T, ...T[]];
158158
pagination?: SharedTypes.TPagination;
159159
order?: {
@@ -173,7 +173,7 @@ export class BaseDomain<TC extends {
173173
*/
174174
getCountByParams: (options: {
175175
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
176-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
176+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
177177
}): Types.TCompareQueryResult => this.model.compareQuery.getCountByParams({ $and: options.params, $or: options.paramsOr }),
178178

179179
/**
@@ -199,7 +199,7 @@ export class BaseDomain<TC extends {
199199
pks: T[],
200200
options: {
201201
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
202-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
202+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
203203
},
204204
): Types.TCompareQueryResult => this.model.compareQuery.getCountByPksAndParams(pks, { $and: options.params, $or: options.paramsOr }),
205205

@@ -215,7 +215,7 @@ export class BaseDomain<TC extends {
215215
*/
216216
getOneByParams: <T extends keyof TC["TableFields"]>(options: {
217217
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
218-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
218+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
219219
selected?: [T, ...T[]];
220220
}): Types.TCompareQueryResult => this.model.compareQuery.getOneByParams({ $and: options.params, $or: options.paramsOr }, options.selected as string[]),
221221

@@ -242,7 +242,7 @@ export class BaseDomain<TC extends {
242242
updateByParams: <T extends Extract<keyof TC["TableFields"], string>[] = Extract<keyof TC["TableFields"], string>[]>(
243243
queryConditions: {
244244
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
245-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
245+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
246246
returningFields?: T;
247247
},
248248
updateFields: Types.TConditionalRawParamsType<TC["UpdateFields"], TC["TableFields"]>,
@@ -307,7 +307,7 @@ export class BaseDomain<TC extends {
307307
*/
308308
async deleteByParams(options: {
309309
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
310-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
310+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
311311
}): Promise<null> {
312312
return this.model.deleteByParams(
313313
{ $and: options.params, $or: options.paramsOr },
@@ -341,7 +341,7 @@ export class BaseDomain<TC extends {
341341
*/
342342
async getArrByParams<T extends keyof TC["TableFields"]>(options: {
343343
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
344-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
344+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
345345
selected?: [T, ...T[]];
346346
pagination?: SharedTypes.TPagination;
347347
order?: {
@@ -382,7 +382,7 @@ export class BaseDomain<TC extends {
382382
pks: T[],
383383
options: {
384384
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
385-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
385+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
386386
},
387387
): Promise<number> {
388388
return this.model.getCountByPksAndParams(
@@ -402,7 +402,7 @@ export class BaseDomain<TC extends {
402402
*/
403403
async getCountByParams(options: {
404404
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
405-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
405+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
406406
}): Promise<number> {
407407
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
408408
}
@@ -412,7 +412,7 @@ export class BaseDomain<TC extends {
412412
*/
413413
async getGuaranteedOneByParams<T extends keyof TC["TableFields"]>(options: {
414414
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
415-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
415+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
416416
selected?: [T, ...T[]];
417417
}): Promise<Pick<TC["TableFields"], T>> {
418418
const one = await this.model.getOneByParams<Pick<TC["TableFields"], T>>(
@@ -437,7 +437,7 @@ export class BaseDomain<TC extends {
437437
*/
438438
async getOneByParams<T extends keyof TC["TableFields"]>(options: {
439439
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
440-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
440+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
441441
selected?: [T, ...T[]];
442442
}): Promise<{ message?: string; one?: Pick<TC["TableFields"], T>; }> {
443443
const one = await this.model.getOneByParams<Pick<TC["TableFields"], T>>(
@@ -482,7 +482,7 @@ export class BaseDomain<TC extends {
482482
async updateByParams<T extends Extract<keyof TC["TableFields"], string>[] = Extract<keyof TC["TableFields"], string>[]>(
483483
queryConditions: {
484484
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
485-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
485+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
486486
returningFields?: T;
487487
},
488488
updateFields: Types.TConditionalRawParamsType<TC["UpdateFields"], TC["TableFields"]>,

src/lib/pg/domain/materialized-view.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type BaseMaterializedViewGeneric = {
99
};
1010

1111
/**
12+
* A class representing a base materialized view with generic type parameters for handling database operations.
13+
*
1214
* @experimental
1315
*/
1416
export class BaseMaterializedView<
@@ -18,8 +20,18 @@ export class BaseMaterializedView<
1820
#name;
1921
#coreFields;
2022

23+
/**
24+
* The model associated with this domain.
25+
*/
2126
model;
2227

28+
/**
29+
* Initializes a new instance of the `BaseMaterializedView` class.
30+
*
31+
* @param data - The domain data object containing the model.
32+
*
33+
* @throws {Error} If `data.model` is not an instance of `Model`.
34+
*/
2335
constructor(data: Types.TDomain<M>) {
2436
if (!(data.model instanceof Model)) {
2537
throw new Error("You need pass data.model extended of PG.Model.BaseMaterializedView");
@@ -31,10 +43,20 @@ export class BaseMaterializedView<
3143
this.#coreFields = this.model.coreFields;
3244
}
3345

46+
/**
47+
* Gets the name of the database materialized view.
48+
*
49+
* @returns The name of the materialized view.
50+
*/
3451
get name() {
3552
return this.#name;
3653
}
3754

55+
/**
56+
* Gets the fields of the database materialized view.
57+
*
58+
* @returns An array of field names in the materialized view.
59+
*/
3860
get coreFields() {
3961
return this.#coreFields;
4062
}
@@ -58,7 +80,7 @@ export class BaseMaterializedView<
5880
*/
5981
getArrByParams: <T extends keyof BMVG["CoreFields"]>(options: {
6082
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
61-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
83+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
6284
selected?: [T, ...T[]];
6385
pagination?: SharedTypes.TPagination;
6486
order?: {
@@ -78,7 +100,7 @@ export class BaseMaterializedView<
78100
*/
79101
getCountByParams: (options: {
80102
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
81-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
103+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
82104
}): Types.TCompareQueryResult => this.model.compareQuery.getCountByParams({ $and: options.params, $or: options.paramsOr }),
83105

84106
/**
@@ -93,7 +115,7 @@ export class BaseMaterializedView<
93115
*/
94116
getOneByParams: <T extends keyof BMVG["CoreFields"]>(options: {
95117
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
96-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
118+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
97119
selected?: [T, ...T[]];
98120
}): Types.TCompareQueryResult => this.model.compareQuery.getOneByParams({ $and: options.params, $or: options.paramsOr }, options.selected as string[]),
99121
};
@@ -114,7 +136,7 @@ export class BaseMaterializedView<
114136
*/
115137
async getArrByParams<T extends keyof BMVG["CoreFields"]>(options: {
116138
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
117-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
139+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
118140
selected?: [T, ...T[]];
119141
pagination?: SharedTypes.TPagination;
120142
order?: {
@@ -141,7 +163,7 @@ export class BaseMaterializedView<
141163
*/
142164
async getCountByParams(options: {
143165
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
144-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
166+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
145167
}): Promise<number> {
146168
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
147169
}
@@ -158,7 +180,7 @@ export class BaseMaterializedView<
158180
*/
159181
async getOneByParams<T extends keyof BMVG["CoreFields"]>(options: {
160182
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
161-
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
183+
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
162184
selected?: [T, ...T[]];
163185
}): Promise<{ message?: string; one?: Pick<BMVG["CoreFields"], T>; }> {
164186
const one = await this.model.getOneByParams<Pick<BMVG["CoreFields"], T>>(
@@ -171,7 +193,14 @@ export class BaseMaterializedView<
171193
return { one };
172194
}
173195

174-
async refresh(): Promise<void> {
175-
return this.model.refresh();
196+
/**
197+
* Refreshes the materialized view.
198+
*
199+
* @param [concurrently=false] - Whether to refresh the view concurrently.
200+
*
201+
* @returns A promise that resolves when the view is refreshed.
202+
*/
203+
async refresh(concurrently: boolean = false): Promise<void> {
204+
return this.model.refresh(concurrently);
176205
}
177206
}

src/lib/pg/domain/sequence.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class BaseSequence<
9090
* Sets the sequence to a specific value.
9191
*
9292
* @param value - The value to set the sequence to.
93+
*
9394
* @returns
9495
*/
9596
async setValue(value: BSG): Promise<void> {

0 commit comments

Comments
 (0)