aboutsummaryrefslogtreecommitdiff
path: root/database.js
diff options
context:
space:
mode:
authorJoelHMikael <joel.h.kronqvist@gmail.com>2022-01-08 16:49:37 +0200
committerJoelHMikael <joel.h.kronqvist@gmail.com>2022-01-08 16:49:37 +0200
commit24709fa862636702fd0430e832463b751fce323e (patch)
tree8bd4eabbf2c7fe4525f66bfe55e3c47994214d79 /database.js
parent4e5fe4711fe46a6af740aadbf23bde86bb5acf69 (diff)
downloadLYLLRuoka-24709fa862636702fd0430e832463b751fce323e.tar.gz
LYLLRuoka-24709fa862636702fd0430e832463b751fce323e.zip
Parsing the shifts (not classes) to the database + some GUI improvements
Diffstat (limited to 'database.js')
-rw-r--r--database.js52
1 files changed, 36 insertions, 16 deletions
diff --git a/database.js b/database.js
index 3a2822a..30396fe 100644
--- a/database.js
+++ b/database.js
@@ -1,35 +1,55 @@
+const mysql = require("mysql2");
+
class Database
{
- constructor(credentials, log)
+ constructor(credentials)
{
this.connection = mysql.createConnection(credentials);
- this.log = log;
}
- query(q)
+ query(query, values)
{
- return new Promise((resolve, reject), () =>
+ return new Promise((resolve, reject) =>
{
- this.connection.query(q, (err, res, fields) =>
+ this.connection.query(query, values, (err, res, fields) =>
{
- if (err)
- {
- this.log(err);
- reject(err);
- }
+ if (err) reject(err);
+ resolve(res);
+ });
+ });
+ }
+ execute(query, values)
+ {
+ return new Promise((resolve, reject) =>
+ {
+ this.connection.execute(query, values, (err, res, fields) =>
+ {
+ if (err) reject(err);
resolve(res);
});
});
+
+ }
+ query_raw(query)
+ {
+ return new Promise((resolve, reject) =>
+ {
+ this.connection.query(query, (err, res, fields) =>
+ {
+ if (err)
+ reject(err)
+ resolve(res);
+ });
+ })
}
close()
{
- this.connection.end(err =>
+ return new Promise((resolve, reject) =>
{
- if (err)
+ this.connection.end(err =>
{
- this.log(err);
- reject(err);
- }
- resolve();
+ if (err) reject(err);
+ resolve();
+ });
});
}
}