telebot-recipe/db_low.js

40 lines
661 B
JavaScript
Raw Normal View History

2019-10-13 14:13:19 +02:00
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
var db = null;
function db_init(db){
db.defaults({ chats:[]}).write();
}
var dbc = function(name){
const db_file = "./db/"+name+".json";
var db = low(new FileSync(db_file));
db_init(db);
return db;
};
const schema = {
recipe:{
id: "reciple_id",
name:"recipe_name",
ingredients:"recipe_ingredients",
},
ingredient:{
id: "ingredient_id",
name: ""
}
};
module.exports = function(name){
this.name = name;
this.db = dbc(name);
this.dump_db = function(obj){
return new Promise((resolve, reject)=>{
resolve(this.db.get("chats").value());
});
};
};