Socialify

Folder ..

Viewing sqlConnectionPool.js
34 lines (27 loc) • 803.0 B

 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
const mariadb = require('mariadb');
const dotenv = require('dotenv');
dotenv.config();

/**
 * @export
 * @class SQLConnectionPool
 */

 module.exports = class SQLConnectionPool {

    static connectionPool = null;

    static createConnectionPool() {
        if (!this.connectionPool) {
            const host = `${process.env.DB_ADDRESS}`;
            const user = process.env.DB_USER;
            const password = `${process.env.DB_PASSWORD}`;
            const database = process.env.DB_DATABASE;

            this.connectionPool = mariadb.createPool({
                host,
                user,
                password,
                database,
                connectionLimit: 32,
                multipleStatements: true
            });
        }

        return this.connectionPool;
    }

}