From 4e5fe4711fe46a6af740aadbf23bde86bb5acf69 Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Fri, 7 Jan 2022 10:58:02 +0200 Subject: Added the DB class & instructions to set up DB --- database.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 database.js (limited to 'database.js') diff --git a/database.js b/database.js new file mode 100644 index 0000000..3a2822a --- /dev/null +++ b/database.js @@ -0,0 +1,37 @@ +class Database +{ + constructor(credentials, log) + { + this.connection = mysql.createConnection(credentials); + this.log = log; + } + query(q) + { + return new Promise((resolve, reject), () => + { + this.connection.query(q, (err, res, fields) => + { + if (err) + { + this.log(err); + reject(err); + } + resolve(res); + }); + }); + } + close() + { + this.connection.end(err => + { + if (err) + { + this.log(err); + reject(err); + } + resolve(); + }); + } +} + +exports.Database = Database; -- cgit v1.2.3