Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated pg-core domain methods #249

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib/mysql/domain/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class BaseDomain<TC extends {

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

async getCountByParams(options: {
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
}): Promise<number> {
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
}
Expand All @@ -103,7 +103,7 @@ export class BaseDomain<TC extends {
*/
async getGuaranteedOneByParams<T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
}): Promise<Pick<TC["TableFields"], T>> {
return this.model.getOneByParams(
Expand All @@ -114,7 +114,7 @@ export class BaseDomain<TC extends {

async getOneByParams<T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<ConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
}): Promise<{ message?: string; one?: Pick<TC["TableFields"], T>; }> {
const one = await this.model.getOneByParams(
Expand Down
26 changes: 13 additions & 13 deletions src/lib/pg/domain/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class BaseDomain<TC extends {
*/
deleteByParams: (options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
}): Types.TCompareQueryResult => this.model.compareQuery.deleteByParams({ $and: options.params, $or: options.paramsOr }),

/**
Expand All @@ -153,7 +153,7 @@ export class BaseDomain<TC extends {
*/
getArrByParams: <T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
pagination?: SharedTypes.TPagination;
order?: {
Expand All @@ -173,7 +173,7 @@ export class BaseDomain<TC extends {
*/
getCountByParams: (options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
}): Types.TCompareQueryResult => this.model.compareQuery.getCountByParams({ $and: options.params, $or: options.paramsOr }),

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

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

Expand All @@ -242,7 +242,7 @@ export class BaseDomain<TC extends {
updateByParams: <T extends Extract<keyof TC["TableFields"], string>[] = Extract<keyof TC["TableFields"], string>[]>(
queryConditions: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
returningFields?: T;
},
updateFields: Types.TConditionalRawParamsType<TC["UpdateFields"], TC["TableFields"]>,
Expand Down Expand Up @@ -307,7 +307,7 @@ export class BaseDomain<TC extends {
*/
async deleteByParams(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
}): Promise<null> {
return this.model.deleteByParams(
{ $and: options.params, $or: options.paramsOr },
Expand Down Expand Up @@ -341,7 +341,7 @@ export class BaseDomain<TC extends {
*/
async getArrByParams<T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
pagination?: SharedTypes.TPagination;
order?: {
Expand Down Expand Up @@ -382,7 +382,7 @@ export class BaseDomain<TC extends {
pks: T[],
options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
},
): Promise<number> {
return this.model.getCountByPksAndParams(
Expand All @@ -402,7 +402,7 @@ export class BaseDomain<TC extends {
*/
async getCountByParams(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
}): Promise<number> {
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
}
Expand All @@ -412,7 +412,7 @@ export class BaseDomain<TC extends {
*/
async getGuaranteedOneByParams<T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
}): Promise<Pick<TC["TableFields"], T>> {
const one = await this.model.getOneByParams<Pick<TC["TableFields"], T>>(
Expand All @@ -437,7 +437,7 @@ export class BaseDomain<TC extends {
*/
async getOneByParams<T extends keyof TC["TableFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
selected?: [T, ...T[]];
}): Promise<{ message?: string; one?: Pick<TC["TableFields"], T>; }> {
const one = await this.model.getOneByParams<Pick<TC["TableFields"], T>>(
Expand Down Expand Up @@ -482,7 +482,7 @@ export class BaseDomain<TC extends {
async updateByParams<T extends Extract<keyof TC["TableFields"], string>[] = Extract<keyof TC["TableFields"], string>[]>(
queryConditions: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<TC["SearchFields"], TC["TableFields"]>>[];
returningFields?: T;
},
updateFields: Types.TConditionalRawParamsType<TC["UpdateFields"], TC["TableFields"]>,
Expand Down
45 changes: 37 additions & 8 deletions src/lib/pg/domain/materialized-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type BaseMaterializedViewGeneric = {
};

/**
* A class representing a base materialized view with generic type parameters for handling database operations.
*
* @experimental
*/
export class BaseMaterializedView<
Expand All @@ -18,8 +20,18 @@ export class BaseMaterializedView<
#name;
#coreFields;

/**
* The model associated with this domain.
*/
model;

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

/**
* Gets the name of the database materialized view.
*
* @returns The name of the materialized view.
*/
get name() {
return this.#name;
}

/**
* Gets the fields of the database materialized view.
*
* @returns An array of field names in the materialized view.
*/
get coreFields() {
return this.#coreFields;
}
Expand All @@ -58,7 +80,7 @@ export class BaseMaterializedView<
*/
getArrByParams: <T extends keyof BMVG["CoreFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
selected?: [T, ...T[]];
pagination?: SharedTypes.TPagination;
order?: {
Expand All @@ -78,7 +100,7 @@ export class BaseMaterializedView<
*/
getCountByParams: (options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
}): Types.TCompareQueryResult => this.model.compareQuery.getCountByParams({ $and: options.params, $or: options.paramsOr }),

/**
Expand All @@ -93,7 +115,7 @@ export class BaseMaterializedView<
*/
getOneByParams: <T extends keyof BMVG["CoreFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
selected?: [T, ...T[]];
}): Types.TCompareQueryResult => this.model.compareQuery.getOneByParams({ $and: options.params, $or: options.paramsOr }, options.selected as string[]),
};
Expand All @@ -114,7 +136,7 @@ export class BaseMaterializedView<
*/
async getArrByParams<T extends keyof BMVG["CoreFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
selected?: [T, ...T[]];
pagination?: SharedTypes.TPagination;
order?: {
Expand All @@ -141,7 +163,7 @@ export class BaseMaterializedView<
*/
async getCountByParams(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
}): Promise<number> {
return this.model.getCountByParams({ $and: options.params, $or: options.paramsOr });
}
Expand All @@ -158,7 +180,7 @@ export class BaseMaterializedView<
*/
async getOneByParams<T extends keyof BMVG["CoreFields"]>(options: {
params: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>;
paramsOr?: Types.TArray2OrMore<Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>>;
paramsOr?: Types.TSearchParams<Types.TConditionalDomainFieldsType<BMVG["SearchFields"], BMVG["CoreFields"]>>[];
selected?: [T, ...T[]];
}): Promise<{ message?: string; one?: Pick<BMVG["CoreFields"], T>; }> {
const one = await this.model.getOneByParams<Pick<BMVG["CoreFields"], T>>(
Expand All @@ -171,7 +193,14 @@ export class BaseMaterializedView<
return { one };
}

async refresh(): Promise<void> {
return this.model.refresh();
/**
* Refreshes the materialized view.
*
* @param [concurrently=false] - Whether to refresh the view concurrently.
*
* @returns A promise that resolves when the view is refreshed.
*/
async refresh(concurrently: boolean = false): Promise<void> {
return this.model.refresh(concurrently);
}
}
1 change: 1 addition & 0 deletions src/lib/pg/domain/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export class BaseSequence<
* Sets the sequence to a specific value.
*
* @param value - The value to set the sequence to.
*
* @returns
*/
async setValue(value: BSG): Promise<void> {
Expand Down
Loading