-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
32 lines (28 loc) · 951 Bytes
/
db.js
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
// Use the MariaDB Node.js Connector
var mariadb = require('mariadb');
require('dotenv').config();
// 1.) Access the Node File System package
//const fs = require("fs");
// 2.) Retrieve the Certificate Authority chain file (wherever you placed it - notice it's just in the Node project root here)
//const serverCert = [fs.readFileSync("skysql_chain.pem", "utf8")];
// Create a connection pool
var pools = [
mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
multipleStatements: true //,
// 3.) Add an "ssl" property to the connection pool configuration, using the serverCert const defined above
/*ssl: {
ca: serverCert
}*/
})
];
// Expose a method to establish connection
module.exports={
getConnection: async function(config_id) {
return pools[config_id].getConnection();
}
}