Initial commit

This commit is contained in:
Oliver 2022-08-08 23:27:23 -06:00
commit 233c1c4da6
14 changed files with 1085 additions and 0 deletions

View file

@ -0,0 +1,25 @@
import { databaseOptions } from "$/types/config";
import fs from "fs";
export class JSONDatabase {
private data = {};
private conf: databaseOptions;
constructor(conf: databaseOptions) {
this.conf = conf;
if (!fs.existsSync(conf.uri)) {
console.error(`Can't find database file, creating default`);
try {
fs.writeFileSync(conf.uri, `{}`);
} catch (_) {
console.log(`Couldn't create database file, ensure the uri is a valid filepath`);
};
};
this.data = JSON.parse(fs.readFileSync(conf.uri, `utf-8`));
};
public shutdown() {
fs.writeFileSync(this.conf.uri, JSON.stringify(this.data));
};
};