Compare commits
5 commits
v2023.02.2
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
c902d92711 | ||
|
90670ebb7b | ||
|
363492aef5 | ||
|
41d589ccbc | ||
|
74f4f42e50 |
2 changed files with 15 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "mit.db",
|
"name": "mit.db",
|
||||||
"version": "2023.02.23-1",
|
"version": "2023.04.12",
|
||||||
"description": "An easy and quick database",
|
"description": "An easy and quick database",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"types": "build/index.d.ts",
|
"types": "build/index.d.ts",
|
||||||
|
@ -11,7 +11,7 @@
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/ThunderNetworkRaD/mit.db.git"
|
"url": "git+https://github.com/ThunderNetworkRaD/mit.db.git"
|
||||||
},
|
},
|
||||||
"author": "Thunder Network Development | Killer Boss Original",
|
"author": "ThunderNetworkRaD | Killer Boss Original",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/ThunderNetworkRaD/mit.db/issues"
|
"url": "https://github.com/ThunderNetworkRaD/mit.db/issues"
|
||||||
|
@ -20,6 +20,6 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.14.0",
|
"@types/node": "^18.14.0",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^5.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/index.ts
18
src/index.ts
|
@ -5,6 +5,9 @@ const writeDB = promisify(fs.writeFile);
|
||||||
|
|
||||||
class MitDB {
|
class MitDB {
|
||||||
readonly db;
|
readonly db;
|
||||||
|
filename: string;
|
||||||
|
options: any;
|
||||||
|
dirname: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -13,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}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,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