You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

import { JSONFilePreset } from 'lowdb/node'
import merge from 'deepmerge'
const db = await JSONFilePreset('./storage/db.json', { runs: [] })
/**
*
*
* @author Björn Hase <me@herr-hase.wtf>
* @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