summaryrefslogtreecommitdiff
path: root/src/database.js
blob: aeea0f0e063db4dd8c7dba4f94eb7e6c8cac19f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
    }
}