Skip to content

Commit

Permalink
Merge pull request #265 from JS-AK/feat/repository-manager/init
Browse files Browse the repository at this point in the history
fix: updated isLoggerEnabled to setLogger
  • Loading branch information
JS-AK authored Dec 10, 2024
2 parents 4315ac8 + cf8455b commit 2e01889
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 100 deletions.
10 changes: 2 additions & 8 deletions src/lib/mysql/model/materialized-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ export class BaseMaterializedView {
this.#logger = logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/mysql/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ export class BaseModel<const T extends readonly string[] = readonly string[]> {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/mysql/model/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,10 @@ export class BaseSequence {
this.#logger = logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/mysql/model/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,10 @@ export class BaseTable<const T extends readonly string[] = readonly string[]> {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/mysql/model/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,10 @@ export class BaseView {
this.#logger = logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
13 changes: 3 additions & 10 deletions src/lib/mysql/repository-manager/repository-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
import { TransactionManager } from "../transaction-manager/transaction-manager.js";

import * as SharedTypes from "../../../shared-types/index.js";
import * as Types from "../model/types.js";

type Model =
| Model.BaseMaterializedView
Expand All @@ -13,14 +14,6 @@ type Model =
| Model.BaseTable
| Model.BaseView;

type Config = {
database: string;
host: string;
password: string;
port: number;
user: string;
};

/**
* RepositoryManager class.
* It is a class for managing MYSQL repositories, query builder factory and transaction manager.
Expand All @@ -46,7 +39,7 @@ export class RepositoryManager<const T extends Record<string, { model: Model; }>
constructor(
repository: T,
options: {
config: Config;
config: Types.TDBCreds;
logger: SharedTypes.TLogger;
isLoggerEnabled?: boolean;
},
Expand All @@ -67,7 +60,7 @@ export class RepositoryManager<const T extends Record<string, { model: Model; }>
continue;
}

r.model.isLoggerEnabled = true;
r.model.setLogger(this.#logger);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/lib/pg/model/materialized-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,10 @@ export class BaseMaterializedView {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/pg/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ export class BaseModel<const T extends readonly string[] = readonly string[]> {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/pg/model/sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ export class BaseSequence {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/pg/model/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,10 @@ export class BaseTable<const T extends readonly string[] = readonly string[]> {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
10 changes: 2 additions & 8 deletions src/lib/pg/model/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,10 @@ export class BaseView {
this.#logger = preparedOptions.logger;
}

set isLoggerEnabled(value: boolean) {
const prev = this.#isLoggerEnabled;

if (prev === value) {
return;
}

setLogger(logger: SharedTypes.TLogger) {
const preparedOptions = setLoggerAndExecutor(
this.pool,
{ isLoggerEnabled: value, logger: this.#logger },
{ isLoggerEnabled: true, logger },
);

this.#executeSql = preparedOptions.executeSql;
Expand Down
13 changes: 3 additions & 10 deletions src/lib/pg/repository-manager/repository-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { QueryBuilderFactory } from "../query-builder/query-builder-factory.js";
import { TransactionManager } from "../transaction-manager/transaction-manager.js";

import * as SharedTypes from "../../../shared-types/index.js";
import * as Types from "../model/types.js";

type Model =
| Model.BaseMaterializedView
Expand All @@ -12,14 +13,6 @@ type Model =
| Model.BaseTable
| Model.BaseView;

type Config = {
database: string;
host: string;
password: string;
port: number;
user: string;
};

/**
* RepositoryManager class.
* It is a class for managing PG repositories, query builder factory and transaction manager.
Expand All @@ -45,7 +38,7 @@ export class RepositoryManager<const T extends Record<string, { model: Model; }>
constructor(
repository: T,
options: {
config: Config;
config: Types.TDBCreds;
logger: SharedTypes.TLogger;
isLoggerEnabled?: boolean;
},
Expand All @@ -68,7 +61,7 @@ export class RepositoryManager<const T extends Record<string, { model: Model; }>
continue;
}

r.model.isLoggerEnabled = true;
r.model.setLogger(this.#logger);
}
}
}
Expand Down

0 comments on commit 2e01889

Please sign in to comment.