import { JSONFilePreset } from 'lowdb/node' import merge from 'deepmerge' const db = await JSONFilePreset('./storage/db.json', { runs: [] }) /** * * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * @link https://git.node001.net/HerrHase/super-hog.git * */ class Db { public constructor(slug) { this.slug = slug this.data = db.data.runs.find((runs) => runs.slug === this.slug) } public async get() { if (this.data === undefined) { this.data = { 'slug': this.slug, 'date_created_at': dayjs().toISOString(), 'date_run_at': dayjs().toISOString() } db.data.runs.push(run) await db.write() } return this.data } public async update(data) { db.data.runs.find((run, index) => { if (run.slug === this.slug) { db.data.runs[index] = merge(db.data.runs[index], data) } }) await db.write() } } export default Db