web/modules/db.js

23 lines
376 B
JavaScript
Raw Normal View History

2021-11-15 10:58:59 +01:00
var mysql = require('mysql2');
2021-11-15 11:35:31 +01:00
2021-11-15 11:56:20 +01:00
let config;
2021-11-15 11:35:31 +01:00
try {
2021-11-15 11:56:20 +01:00
config = require('../config');
2021-11-15 11:35:31 +01:00
} catch (e) {
console.log('No config file found');
2021-11-15 11:56:20 +01:00
process.exit(0);
2021-11-15 11:35:31 +01:00
}
2021-11-15 10:58:59 +01:00
2021-11-15 11:05:44 +01:00
function connect() {
2021-11-15 10:58:59 +01:00
const connection = mysql.createConnection(config.db);
return connection;
}
2021-11-21 18:07:43 +01:00
function disconnect(connection) {
connection.end();
}
2021-11-15 10:58:59 +01:00
module.exports = {
2021-11-21 18:07:43 +01:00
connect,
disconnect
2021-11-15 10:58:59 +01:00
}