Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
m4lab_tv1
User Account
Commits
4253099f
Commit
4253099f
authored
Sep 16, 2021
by
Rosanny Sihombing
Browse files
using connection pools
parent
55458af0
Changes
1
Hide whitespace changes
Inline
Side-by-side
config/dbconn.ts
View file @
4253099f
...
...
@@ -4,59 +4,34 @@ var env = process.env.NODE_ENV || 'testing'
const
config
=
require
(
'
./config
'
)[
env
]
// ==== USER ACOOUNT DB CONNECTION ====
var
userConnection
=
mysql
.
create
Connection
({
const
userConnection
=
mysql
.
create
Pool
({
host
:
config
.
database
.
host
,
user
:
config
.
database
.
user
,
password
:
config
.
database
.
password
,
port
:
config
.
database
.
port
,
database
:
config
.
database
.
dbUser
,
multipleStatements
:
true
})
waitForConnections
:
true
,
connectionLimit
:
10
,
queueLimit
:
0
});
userConnection
.
connect
(
function
(
err
)
{
if
(
err
)
throw
err
})
userConnection
.
query
(
'
USE
'
+
config
.
database
.
dbUser
)
// ALTERNATIVE approach: close db connection manually after every query
/*
var dbconn = function dbconn(query, values, next) {
var connection = mysql.createConnection({
host: config.database.host,
user: config.database.user,
password: config.database.password,
port: config.database.port,
database: config.database.db
})
connection.connect(function(err) {
if (err) throw err;
})
connection.query(query, values, function(err) {
connection.end(); // close the connection
if (err) {
throw err;
}
// Execute the callback
next.apply(this, arguments);
});
}
*/
// ==== PROJECT DB CONNECTION ====
var
projectConnection
=
mysql
.
create
Connection
({
const
projectConnection
=
mysql
.
create
Pool
({
host
:
config
.
database
.
host_project
,
user
:
config
.
database
.
user
,
password
:
config
.
database
.
password
,
port
:
config
.
database
.
port
,
database
:
config
.
database
.
dbProject
})
database
:
config
.
database
.
dbProject
,
waitForConnections
:
true
,
connectionLimit
:
10
,
queueLimit
:
0
});
projectConnection
.
connect
(
function
(
err
)
{
if
(
err
)
throw
err
})
projectConnection
.
query
(
'
USE
'
+
config
.
database
.
dbProject
)
var
connection
=
{
const
connection
=
{
user
:
userConnection
,
project
:
projectConnection
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment