// (C) Copyright 2015 Moodle Pty Ltd. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import { SQLiteDBRecordValues } from '@classes/sqlitedb'; import { CoreLogger } from '@singletons/logger'; import { CoreDatabaseTable, CoreDatabaseConditions, GetDBRecordPrimaryKey, CoreDatabaseReducer, CoreDatabaseQueryOptions, } from './database-table'; /** * Database table proxy used to debug runtime operations. * * This proxy should only be used for development purposes. */ export class CoreDebugDatabaseTable< DBRecord extends SQLiteDBRecordValues = SQLiteDBRecordValues, PrimaryKeyColumn extends keyof DBRecord = 'id', PrimaryKey extends GetDBRecordPrimaryKey = GetDBRecordPrimaryKey > extends CoreDatabaseTable { protected target: CoreDatabaseTable; protected logger: CoreLogger; constructor(target: CoreDatabaseTable) { super(target.getDatabase(), target.getTableName(), target.getPrimaryKeyColumns()); this.target = target; this.logger = CoreLogger.getInstance(`CoreDatabase[${this.tableName}]`); } /** * @inheritdoc */ initialize(): Promise { this.logger.log('initialize', this.target); return this.target.initialize(); } /** * @inheritdoc */ destroy(): Promise { this.logger.log('destroy'); return this.target.destroy(); } /** * @inheritdoc */ getMany(conditions?: Partial, options?: Partial>): Promise { this.logger.log('getMany', conditions, options); return this.target.getMany(conditions, options); } /** * @inheritdoc */ getManyWhere(conditions: CoreDatabaseConditions): Promise { this.logger.log('getManyWhere', conditions); return this.target.getManyWhere(conditions); } /** * @inheritdoc */ getOne( conditions?: Partial, options?: Partial, 'offset' | 'limit'>>, ): Promise { this.logger.log('getOne', conditions, options); return this.target.getOne(conditions, options); } /** * @inheritdoc */ getOneByPrimaryKey(primaryKey: PrimaryKey): Promise { this.logger.log('findByPrimaryKey', primaryKey); return this.target.getOneByPrimaryKey(primaryKey); } /** * @inheritdoc */ reduce(reducer: CoreDatabaseReducer, conditions?: CoreDatabaseConditions): Promise { this.logger.log('reduce', reducer, conditions); return this.target.reduce(reducer, conditions); } /** * @inheritdoc */ hasAny(conditions?: Partial): Promise { this.logger.log('hasAny', conditions); return this.target.hasAny(conditions); } /** * @inheritdoc */ count(conditions?: Partial): Promise { this.logger.log('count', conditions); return this.target.count(conditions); } /** * @inheritdoc */ insert(record: DBRecord): Promise { this.logger.log('insert', record); return this.target.insert(record); } /** * @inheritdoc */ update(updates: Partial, conditions?: Partial): Promise { this.logger.log('update', updates, conditions); return this.target.update(updates, conditions); } /** * @inheritdoc */ updateWhere(updates: Partial, conditions: CoreDatabaseConditions): Promise { this.logger.log('updateWhere', updates, conditions); return this.target.updateWhere(updates, conditions); } /** * @inheritdoc */ delete(conditions?: Partial): Promise { this.logger.log('delete', conditions); return this.target.delete(conditions); } /** * @inheritdoc */ deleteByPrimaryKey(primaryKey: PrimaryKey): Promise { this.logger.log('deleteByPrimaryKey', primaryKey); return this.target.deleteByPrimaryKey(primaryKey); } }