summaryrefslogtreecommitdiff
path: root/source/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'source/database.js')
-rw-r--r--source/database.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/database.js b/source/database.js
new file mode 100644
index 0000000..78e8a1f
--- /dev/null
+++ b/source/database.js
@@ -0,0 +1,20 @@
+const mysql = require('mysql2')
+const logger = require('./logger')()
+require('dotenv').config()
+
+// Authenticates with SQL server and send query
+class Database {
+ constructor(x) {
+ this.pool = mysql.createPool({
+ host: process.env.MYSQL_HOST,
+ user: process.env.MYSQL_USER,
+ password: process.env.MYSQL_PASSWORD,
+ database: x
+ }).promise()
+ }
+
+ async Query(x) {try {return await this.pool.query(x)} catch (err) {logger.Error(err)}}
+}
+
+module.exports = (x) => {return new Database(x)}
+