2020-08-16 23:28:41 -07:00
|
|
|
const mysql = require("mysql2");
|
2020-04-22 11:51:36 -07:00
|
|
|
|
2020-04-22 15:53:59 -07:00
|
|
|
let globalDb;
|
|
|
|
|
2020-04-22 11:51:36 -07:00
|
|
|
async function connectToDb() {
|
2020-04-22 15:53:59 -07:00
|
|
|
if (globalDb) {
|
|
|
|
return globalDb;
|
|
|
|
}
|
|
|
|
|
2020-08-16 23:28:41 -07:00
|
|
|
globalDb = mysql
|
|
|
|
.createConnection({
|
|
|
|
host: "impress.openneo.net",
|
|
|
|
user: process.env["IMPRESS_MYSQL_USER"],
|
|
|
|
password: process.env["IMPRESS_MYSQL_PASSWORD"],
|
|
|
|
database: "openneo_impress",
|
|
|
|
})
|
|
|
|
// We upgrade to promises here, instead of using the mysql2/promise import,
|
|
|
|
// for compatibility with Honeycomb's automatic tracing.
|
|
|
|
.promise();
|
2020-04-22 11:51:36 -07:00
|
|
|
|
2020-04-22 15:53:59 -07:00
|
|
|
return globalDb;
|
2020-04-22 11:51:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = connectToDb;
|