-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
35 lines (29 loc) · 832 Bytes
/
database.js
File metadata and controls
35 lines (29 loc) · 832 Bytes
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
const util = require('util')
const mysql = require('mysql')
const config=require("./config.json");
const pool = mysql.createPool
({
connectionLimit: 10,
host: "localhost",
user: config.sqluser,
password: config.sqlpass,
database: config.sqldatabase
})
// Ping database to check for common exception errors.
pool.getConnection((err, connection) =>
{
if(err)
{
if (err.code === 'PROTOCOL_CONNECTION_LOST')
console.error('Database connection was closed.')
if (err.code === 'ER_CON_COUNT_ERROR')
console.error('Database has too many connections.')
if (err.code === 'ECONNREFUSED')
console.error('Database connection was refused.')
}
if (connection) connection.release()
return
})
// Promisify for Node.js async/await.
pool.query = util.promisify(pool.query)
module.exports = pool