aboutsummaryrefslogtreecommitdiff
path: root/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'database.js')
-rw-r--r--database.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/database.js b/database.js
new file mode 100644
index 0000000..30396fe
--- /dev/null
+++ b/database.js
@@ -0,0 +1,57 @@
+const mysql = require("mysql2");
+
+class Database
+{
+ constructor(credentials)
+ {
+ this.connection = mysql.createConnection(credentials);
+ }
+ query(query, values)
+ {
+ return new Promise((resolve, reject) =>
+ {
+ this.connection.query(query, values, (err, res, fields) =>
+ {
+ 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()
+ {
+ return new Promise((resolve, reject) =>
+ {
+ this.connection.end(err =>
+ {
+ if (err) reject(err);
+ resolve();
+ });
+ });
+ }
+}
+
+exports.Database = Database;