From 24709fa862636702fd0430e832463b751fce323e Mon Sep 17 00:00:00 2001 From: JoelHMikael Date: Sat, 8 Jan 2022 16:49:37 +0200 Subject: Parsing the shifts (not classes) to the database + some GUI improvements --- database.js | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'database.js') 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(); + }); }); } } -- cgit v1.2.3