mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Release v1.0.0 🎉
This commit is contained in:
36
lib/services/store.js
Executable file
36
lib/services/store.js
Executable file
@@ -0,0 +1,36 @@
|
||||
const path = require('path');
|
||||
const DB_PATH = path.dirname(require.main.filename) + '/conf/store.json';
|
||||
|
||||
const FileAsync = require('lowdb/adapters/FileAsync');
|
||||
const adapter = new FileAsync(DB_PATH);
|
||||
const low = require('lowdb');
|
||||
|
||||
const lowdb = low(adapter);
|
||||
|
||||
class Store {
|
||||
constructor(name) {
|
||||
this._name = name;
|
||||
this._db = null;
|
||||
}
|
||||
|
||||
get warmup() {
|
||||
return new Promise(resolve => {
|
||||
lowdb.then(db => {
|
||||
this._db = db;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
set knownListings(value) {
|
||||
if (!Array.isArray(value)) throw Error('Not a valid array');
|
||||
|
||||
return this._db.set(this._name, value).write();
|
||||
}
|
||||
|
||||
get knownListings() {
|
||||
return this._db.get(this._name).value() || [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Store;
|
||||
Reference in New Issue
Block a user