Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps-dev): bump @types/node from 20.4.9 to 20.5.7 #417

Merged
merged 15 commits into from
Aug 30, 2023
7 changes: 5 additions & 2 deletions databases/mock_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import events from 'events';

export const Database = class extends events.EventEmitter {
private settings: Settings;
public mock: any;
constructor(settings:Settings) {
super();
this.settings = {
writeInterval: 1,
...settings,
};
settings.mock = this;
this.settings = settings;
console.log("Initialized")
}

close(cb: ()=>{}) {
Expand All @@ -29,8 +32,8 @@ export const Database = class extends events.EventEmitter {
this.emit('get', key, cb);
}

init(cb:()=>{}) {
this.emit('init', cb);
async init(cb:()=>{}) {
this.emit('init', cb());
}

remove(key:string, cb:()=>{}) {
Expand Down
2 changes: 1 addition & 1 deletion databases/mongodb_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const Database = class extends AbstractDatabase {

clearPing() {
if (this.interval) {
clearInterval(this.interval);
clearInterval(this.interval[Symbol.toPrimitive]());
}
}

Expand Down
5 changes: 2 additions & 3 deletions databases/mysql_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import util from 'util';
import {BulkObject} from './cassandra_db';

export const Database = class extends AbstractDatabase {
private _mysqlSettings: Settings;
private readonly _mysqlSettings: Settings;
private _pool: any;
constructor(settings:Settings) {
super();
Expand All @@ -45,8 +45,7 @@ export const Database = class extends AbstractDatabase {
try {
return await new Promise((resolve, reject) => {
options = {timeout: this.settings.queryTimeout, ...options};
// @ts-ignore
this._pool && this._pool.query(options, (err, ...args) => err != null ? reject(err) : resolve(args));
this._pool && this._pool.query(options, (err:Error, ...args:string[]) => err != null ? reject(err) : resolve(args));
});
} catch (err:any) {
this.logger.error(`${err.fatal ? 'Fatal ' : ''}MySQL error: ${err.stack || err}`);
Expand Down
22 changes: 9 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const makeDoneCallback = (callback: (err?:any)=>{}, deprecated:(err:any)=>{}) =>
};

export const Database = class {
private type: any;
private readonly type: any;
private dbModule: any;
private readonly dbSettings: any;
private readonly wrapperSettings: any | {};
private readonly logger: Function | null;
private readonly db: any;
private db: any;
private metrics: any;
/**
* @param type The type of the database
Expand All @@ -60,7 +60,7 @@ export const Database = class {
* from another logging library should also work, but performance may be reduced if the logger
* object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
*/
constructor(type: undefined | string, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger:any = null) {
constructor(type: undefined | string, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger: any = null) {
if (!type) {
type = 'sqlite';
dbSettings = null;
Expand All @@ -69,25 +69,21 @@ export const Database = class {

// saves all settings and require the db module
this.type = type;
this.dbModule = require(`./databases/${type}_db`);
this.dbSettings = dbSettings;
this.wrapperSettings = wrapperSettings;
this.logger = normalizeLogger(logger);
const db = new this.dbModule.Database(this.dbSettings);
db.logger = this.logger;
this.db = new DatabaseCache(db, this.wrapperSettings, this.logger);

// Expose the cache wrapper's metrics to the user. See lib/CacheAndBufferLayer.js for details.
//
// WARNING: This feature is EXPERIMENTAL -- do not assume it will continue to exist in its
// current form in a future version.
this.metrics = this.db.metrics;
}

/**
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
*/
init(callback = null) {
async init(callback = null) {
this.dbModule = await import(`./databases/${this.type}_db`);
const db = new this.dbModule.Database(this.dbSettings);
db.logger = this.logger;
this.db = new DatabaseCache(db, this.wrapperSettings, this.logger);
this.metrics = this.db.metrics;
if (callback != null) {
return cbDb.init.call(this.db);
}
Expand Down
Loading