const sqlite3 = require('sqlite3');//.verbose(); function db_init(db){ db.run("CREATE TABLE IF NOT EXISTS chats (id integer PRIMARY KEY AUTOINCREMENT, chat_id integer NOT NULL);"); } var dbc = function(name){ const db_file = "./db/"+name+".sqlite3"; var db = new sqlite3.Database(db_file); db_init(db); return db; }; const schema = { chats:{ id: "chat_id", lang:"chat_lang", tz:"chat_tz", geo:"chat_geo", }, }; function db_request(db,req,requirements,cb){ for(var i in requirements){ if(!requirements[i]) return cb("Error in Arguments: "+requirements,null); } db.all(req, requirements, (err,res)=>{ cb(err,res) }); } module.exports = function(name){ this.name = name; this.db = dbc(name); this.dump_db = function(obj){ return new Promise((resolve, reject)=>{ this.db.all("SELECT * FROM chats",[],(err,res)=>{ console.log(res); resolve(res); }); }); };