@onurege3467/zerohelper
Version:
ZeroHelper is a versatile high-performance utility library and database framework for Node.js, fully written in TypeScript.
49 lines (48 loc) • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IDatabase = void 0;
const telemetry_1 = require("./telemetry");
/**
* Defines the common interface that all database adapters must implement.
*/
class IDatabase {
constructor() {
this.hooks = {
beforeInsert: [],
afterInsert: [],
beforeUpdate: [],
afterUpdate: [],
beforeDelete: [],
afterDelete: [],
};
}
/**
* Registers a lifecycle hook.
*/
on(hook, fn) {
if (this.hooks[hook]) {
this.hooks[hook].push(fn);
}
}
async runHooks(hook, table, data) {
for (const fn of this.hooks[hook]) {
await fn(table, data);
}
}
/**
* Returns performance metrics for the database and cache.
*/
getMetrics() {
return telemetry_1.telemetry.getMetrics();
}
recordMetric(operation, table, duration) {
telemetry_1.telemetry.recordDb({
operation,
table,
duration,
timestamp: Date.now()
});
}
}
exports.IDatabase = IDatabase;
exports.default = IDatabase;