aboutsummaryrefslogtreecommitdiff
path: root/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'database.js')
-rw-r--r--database.js37
1 files changed, 37 insertions, 0 deletions
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;