aboutsummaryrefslogtreecommitdiff
path: root/database.js
diff options
context:
space:
mode:
authorJoelHMikael <53561102+JoelHMikael@users.noreply.github.com>2022-01-18 18:57:53 +0200
committerGitHub <noreply@github.com>2022-01-18 18:57:53 +0200
commita259127b9fa0349c73340c882f6525f27f7caaed (patch)
treead18984d3031ce6bc7ccb549415c58d77672a53f /database.js
parent8f711465194f6779271825bdb2413658880f4c18 (diff)
parentedf044c1e1e0c751229549dd9d14062b230149be (diff)
downloadLYLLRuoka-a259127b9fa0349c73340c882f6525f27f7caaed.tar.gz
LYLLRuoka-a259127b9fa0349c73340c882f6525f27f7caaed.zip
Merge pull request #1 from JoelHMikael/MYSQLDB
Mysqldb
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;