0
0
Fork 0

Initial commit

This commit is contained in:
Oliver 2022-12-23 15:19:37 -06:00 committed by GitHub
commit 56f2195962
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 1121 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));
};
};