summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/database.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/database.js b/src/database.js
new file mode 100644
index 0000000..aeea0f0
--- /dev/null
+++ b/src/database.js
@@ -0,0 +1,38 @@
+const mysql = require('mysql2')
+const logger = require('./logger')()
+require('dotenv').config()
+
+// Authenticates with SQL server and send query
+class Database {
+ constructor(x) {
+ this.host = x.host
+ this.user = x.username
+ this.password = x.password
+ this.database = x.database
+ }
+
+ CreatePool() {
+ return mysql.createPool({
+ host: this.host,
+ user: this.user,
+ password: this.password,
+ database: this.database
+ }).promise()
+ }
+
+ Query(x) {return this.pool.query(x)}
+}
+
+module.exports = (x) => {
+ const database = new Database(x)
+ const pools = []
+ const createPool = () => {
+ pools.push(database.CreatePool())
+ }
+
+ return {
+ pools: pools,
+ createPool: createPool
+ }
+}
+