.
This commit is contained in:
parent
363492aef5
commit
90670ebb7b
1 changed files with 11 additions and 9 deletions
20
src/index.ts
20
src/index.ts
|
@ -5,8 +5,9 @@ const writeDB = promisify(fs.writeFile);
|
||||||
|
|
||||||
class MitDB {
|
class MitDB {
|
||||||
readonly db;
|
readonly db;
|
||||||
fn: string;
|
filename: string;
|
||||||
options?: any;
|
options: any;
|
||||||
|
dirname: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -15,17 +16,18 @@ class MitDB {
|
||||||
* @param options Options to pass in the constructor
|
* @param options Options to pass in the constructor
|
||||||
* @param options.dirname where to put the database?
|
* @param options.dirname where to put the database?
|
||||||
*/
|
*/
|
||||||
constructor(fn: string, options?: { dirname: string }) {
|
constructor(filename: string, options?: { dirname: string }) {
|
||||||
let dirname;
|
|
||||||
if (options && options.dirname) {
|
if (options && options.dirname) {
|
||||||
dirname = options.dirname;
|
this.dirname = options.dirname;
|
||||||
} else {
|
} 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) {
|
forEach(callback: (value: any, key: any) => void) {
|
||||||
const file = fs.readFileSync(this.db);
|
const file = fs.readFileSync(this.db);
|
||||||
|
|
Loading…
Reference in a new issue