codeworld
Version:
A simple Database & Discord.js module.
50 lines (41 loc) • 1.36 kB
JavaScript
const path = require('path');
const { ensureDirectory, load, save } = require('./Functions/_utils');
const Set = require('./Functions/Set');
const Get = require('./Functions/Get');
const Fetch = require('./Functions/Fetch');
const Delete = require('./Functions/Delete');
const All = require('./Functions/All');
const Push = require('./Functions/Push');
const UnPush = require('./Functions/UnPush');
class DB {
constructor(filePath = path.resolve(__dirname, '..', '..', '..', 'CodeWorld', 'codeworld.json')) {
this.filePath = filePath;
ensureDirectory(this.filePath);
this.data = load(this.filePath);
}
set(key, value) {
return Set(this.data, this.filePath, key, value, save);
}
get(key) {
return Get(this.data, key);
}
fetch(key) {
return Fetch(this.data, key);
}
delete(key) {
return Delete(this.data, this.filePath, key, save);
}
all() {
return All(this.data);
}
allArray() {
return Object.entries(this.data);
}
push(key, value) {
return Push(this.data, this.filePath, key, value, save);
}
unpush(key, value) {
return UnPush(this.data, this.filePath, key, value, save);
}
}
module.exports = new DB();