This commit is contained in:
Killer Boss Original 2023-04-12 18:37:16 +02:00 committed by GitHub
parent 363492aef5
commit 90670ebb7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,8 +5,9 @@ const writeDB = promisify(fs.writeFile);
class MitDB {
readonly db;
fn: string;
options?: any;
filename: string;
options: any;
dirname: string;
/**
* @constructor
@ -15,17 +16,18 @@ class MitDB {
* @param options Options to pass in the constructor
* @param options.dirname where to put the database?
*/
constructor(fn: string, options?: { dirname: string }) {
let dirname;
constructor(filename: string, options?: { dirname: string }) {
if (options && options.dirname) {
dirname = options.dirname;
this.dirname = options.dirname;
} else {
dirname = 'data';
this.dirname = 'data';
}
if (!fs.existsSync(dirname)) fs.mkdirSync(dirname);
this.filename = filename;
this.db = `./${dirname}/${fn}`
if (!fs.existsSync(this.dirname)) fs.mkdirSync(this.dirname);
this.db = `./${this.dirname}/${this.filename}`;
}
/**
@ -99,7 +101,7 @@ class MitDB {
/**
*
* @param callbackfn
* @param callbackfilename
*/
forEach(callback: (value: any, key: any) => void) {
const file = fs.readFileSync(this.db);