dbconn.ts 1002 Bytes
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
import mysql from 'mysql2'
Rosanny Sihombing's avatar
Rosanny Sihombing committed
2

Rosanny Sihombing's avatar
Rosanny Sihombing committed
3
var env = process.env.NODE_ENV || 'testing'
Rosanny Sihombing's avatar
Rosanny Sihombing committed
4
const config = require('./config')[env]
Rosanny Sihombing's avatar
Rosanny Sihombing committed
5
6

// ==== USER ACOOUNT DB CONNECTION ====
Rosanny Sihombing's avatar
Rosanny Sihombing committed
7
const userConnection = mysql.createPool({
Rosanny Sihombing's avatar
Rosanny Sihombing committed
8
9
10
11
    host: config.database.host,
    user: config.database.user,
    password: config.database.password,
    port: config.database.port,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
12
    database: config.database.dbUser,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
13
14
15
16
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
});
Rosanny Sihombing's avatar
Rosanny Sihombing committed
17

Rosanny Sihombing's avatar
Rosanny Sihombing committed
18
userConnection.query('USE '+config.database.dbUser)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
19
20

// ==== PROJECT DB CONNECTION ====
Rosanny Sihombing's avatar
Rosanny Sihombing committed
21
const projectConnection = mysql.createPool({
22
    host: config.database.host_project,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
23
24
25
    user: config.database.user,
    password: config.database.password,
    port: config.database.port,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
26
27
28
29
30
    database: config.database.dbProject,
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
});
Rosanny Sihombing's avatar
Rosanny Sihombing committed
31
32
33

projectConnection.query('USE '+config.database.dbProject)

Rosanny Sihombing's avatar
Rosanny Sihombing committed
34
const connection = {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
35
36
37
38
    user: userConnection,
    project: projectConnection
}

Rosanny Sihombing's avatar
Rosanny Sihombing committed
39
export = connection