feat: Add DatabasesService in services/databases

Implemented new class DatabasesService for handling database interactions in place of multiple database services. This centralizes the interaction with different databases - MariaDb and MongoDB with added logging utility for monitoring query results. Also, a test instance of the DatabasesService was created as 'justForTesting' for development purposes.
This commit is contained in:
Mathis 2024-05-14 23:35:11 +02:00
parent 6b944301cc
commit 9c45029706

View File

@ -0,0 +1,34 @@
import {MariadbService} from "@services/databases/mariadb.service";
import {MongodbService} from "@services/databases/mongodb.service";
import {LogsUtils} from "@utils/logs.util";
interface MariaDbStatusResult {
fieldCount: number;
affectedRows: number;
insertId: number;
info: string;
serverStatus: number;
warningStatus: number;
changedRows: number;
}
class DatabasesService {
private readonly _appName;
private readonly maria: MariadbService;
private readonly mongo: MongodbService;
private readonly logs: LogsUtils;
constructor(appName?: string) {
this._appName = appName || 'App';
this.maria = new MariadbService(this._appName + ' DbInteractions');
this.mongo = new MongodbService(this._appName + ' DbInteractions');
this.logs = new LogsUtils(this._appName + ' DbInteractions');
}
async getAllUsers() {
const result = await this.maria.query("SELECT * FROM users");
this.logs.debug('Fetching users from database', result)
return result;
}
}
export const justForTesting = new DatabasesService('OnlyDevs')