telebot-template/db_low.js

37 lines
602 B
JavaScript
Raw Permalink Normal View History

2019-09-25 17:21:24 +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 = {
chats:{
id: "chat_id",
lang:"chat_lang",
tz:"chat_tz",
geo:"chat_geo",
},
};
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());
});
};
};