dbconn.ts 1 KB
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
updates    
Rosanny Sihombing committed
3
4
var env = process.env.NODE_ENV || 'development';
const config = require('./config')[env]
Rosanny Sihombing's avatar
Rosanny Sihombing committed
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
39

// ==== USER ACOOUNT DB CONNECTION ====
var userConnection = mysql.createConnection({
    host: config.database.host,
    user: config.database.user,
    password: config.database.password,
    port: config.database.port,
    database: config.database.dbUser,
    multipleStatements: true
})

userConnection.connect(function(err) {
    if (err) throw err;
})
userConnection.query('USE '+config.database.dbUser)

// ==== PROJECT DB CONNECTION ====
var projectConnection = mysql.createConnection({
    host: config.database.host_project,
    user: config.database.user,
    password: config.database.password,
    port: config.database.port,
    database: config.database.dbProject
})

projectConnection.connect(function(err) {
    if (err) throw err;
})
projectConnection.query('USE '+config.database.dbProject)

var connection = {
    user: userConnection,
    project: projectConnection
}

Rosanny Sihombing's avatar
updates    
Rosanny Sihombing committed
40
export = connection