From cf8455b846f6fc6d901c95c50bf8d280c18e6a64 Mon Sep 17 00:00:00 2001 From: Anton Date: Tue, 10 Dec 2024 19:14:59 +0300 Subject: [PATCH] fix: updated isLoggerEnabled to setLogger --- src/lib/mysql/model/materialized-view.ts | 10 ++-------- src/lib/mysql/model/model.ts | 10 ++-------- src/lib/mysql/model/sequence.ts | 10 ++-------- src/lib/mysql/model/table.ts | 10 ++-------- src/lib/mysql/model/view.ts | 10 ++-------- .../mysql/repository-manager/repository-manager.ts | 13 +++---------- src/lib/pg/model/materialized-view.ts | 10 ++-------- src/lib/pg/model/model.ts | 10 ++-------- src/lib/pg/model/sequence.ts | 10 ++-------- src/lib/pg/model/table.ts | 10 ++-------- src/lib/pg/model/view.ts | 10 ++-------- src/lib/pg/repository-manager/repository-manager.ts | 13 +++---------- 12 files changed, 26 insertions(+), 100 deletions(-) diff --git a/src/lib/mysql/model/materialized-view.ts b/src/lib/mysql/model/materialized-view.ts index 6609f4d..8cb7ab6 100644 --- a/src/lib/mysql/model/materialized-view.ts +++ b/src/lib/mysql/model/materialized-view.ts @@ -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; diff --git a/src/lib/mysql/model/model.ts b/src/lib/mysql/model/model.ts index 131c5f0..e157f05 100644 --- a/src/lib/mysql/model/model.ts +++ b/src/lib/mysql/model/model.ts @@ -58,16 +58,10 @@ export class BaseModel { 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; diff --git a/src/lib/mysql/model/sequence.ts b/src/lib/mysql/model/sequence.ts index be0c43b..3d55713 100644 --- a/src/lib/mysql/model/sequence.ts +++ b/src/lib/mysql/model/sequence.ts @@ -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; diff --git a/src/lib/mysql/model/table.ts b/src/lib/mysql/model/table.ts index ea14074..b555fd2 100644 --- a/src/lib/mysql/model/table.ts +++ b/src/lib/mysql/model/table.ts @@ -93,16 +93,10 @@ export class BaseTable { 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; diff --git a/src/lib/mysql/model/view.ts b/src/lib/mysql/model/view.ts index 98cfdc7..19323b8 100644 --- a/src/lib/mysql/model/view.ts +++ b/src/lib/mysql/model/view.ts @@ -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; diff --git a/src/lib/mysql/repository-manager/repository-manager.ts b/src/lib/mysql/repository-manager/repository-manager.ts index b5e4356..0c032c4 100644 --- a/src/lib/mysql/repository-manager/repository-manager.ts +++ b/src/lib/mysql/repository-manager/repository-manager.ts @@ -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 @@ -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. @@ -46,7 +39,7 @@ export class RepositoryManager constructor( repository: T, options: { - config: Config; + config: Types.TDBCreds; logger: SharedTypes.TLogger; isLoggerEnabled?: boolean; }, @@ -67,7 +60,7 @@ export class RepositoryManager continue; } - r.model.isLoggerEnabled = true; + r.model.setLogger(this.#logger); } } } diff --git a/src/lib/pg/model/materialized-view.ts b/src/lib/pg/model/materialized-view.ts index 42dec9b..249bc4c 100644 --- a/src/lib/pg/model/materialized-view.ts +++ b/src/lib/pg/model/materialized-view.ts @@ -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; diff --git a/src/lib/pg/model/model.ts b/src/lib/pg/model/model.ts index 07aa587..abae728 100644 --- a/src/lib/pg/model/model.ts +++ b/src/lib/pg/model/model.ts @@ -54,16 +54,10 @@ export class BaseModel { 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; diff --git a/src/lib/pg/model/sequence.ts b/src/lib/pg/model/sequence.ts index 7d44c56..b7bf39b 100644 --- a/src/lib/pg/model/sequence.ts +++ b/src/lib/pg/model/sequence.ts @@ -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; diff --git a/src/lib/pg/model/table.ts b/src/lib/pg/model/table.ts index 3489eb9..de34c2d 100644 --- a/src/lib/pg/model/table.ts +++ b/src/lib/pg/model/table.ts @@ -89,16 +89,10 @@ export class BaseTable { 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; diff --git a/src/lib/pg/model/view.ts b/src/lib/pg/model/view.ts index adfd282..40ca4ff 100644 --- a/src/lib/pg/model/view.ts +++ b/src/lib/pg/model/view.ts @@ -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; diff --git a/src/lib/pg/repository-manager/repository-manager.ts b/src/lib/pg/repository-manager/repository-manager.ts index cea445e..3edd506 100644 --- a/src/lib/pg/repository-manager/repository-manager.ts +++ b/src/lib/pg/repository-manager/repository-manager.ts @@ -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 @@ -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. @@ -45,7 +38,7 @@ export class RepositoryManager constructor( repository: T, options: { - config: Config; + config: Types.TDBCreds; logger: SharedTypes.TLogger; isLoggerEnabled?: boolean; }, @@ -68,7 +61,7 @@ export class RepositoryManager continue; } - r.model.isLoggerEnabled = true; + r.model.setLogger(this.#logger); } } }