const knex = require('knex');

class Db {
	connect(config) {
		this.db = knex(config);
	}
	query(sql, params) {
		return this.db.raw(sql, params);
	}
	close() {
		return new Promise((resolve, reject) => {
			this.db.destroy(err => err ? reject(err) : resolve());
		});
	}
}

module.exports = new Db();

@@ -43,23 +43,90 @@
 %09con
-nect(config) %7B%0A
+structor() %7B%0A%09%09this.db = null;%0A%09%7D%0A%09connect(config) %7B%0A%09%09if(!this.isConnected()) %7B%0A%09
 %09%09th
@@ -147,16 +147,20 @@
 onfig);%0A
+%09%09%7D%0A
 %09%7D%0A%09quer
@@ -219,65 +219,37 @@
 %09%7D%0A%09
-close() %7B%0A%09%09return new Promise((resolve, rej
+async disconn
 ect
+(
 )
- =%3E
  %7B%0A%09%09
-%09
+await 
 this
@@ -264,51 +264,60 @@
 roy(
-err =%3E err ? reject(err) : resolve());%0A%09%09%7D)
+);%0A%09%09this.db = null;%0A%09%7D%0A%09isConnected() %7B%0A%09%09!!this.db
 ;%0A%09%7D

Fix db connection management