InitalCommit
This commit is contained in:
46
config/database.js
Normal file
46
config/database.js
Normal file
@@ -0,0 +1,46 @@
|
||||
require('dotenv').config();
|
||||
const sql = require('mssql');
|
||||
|
||||
const config = {
|
||||
server: process.env.DB_SERVER || 'localhost',
|
||||
port: parseInt(process.env.DB_PORT) || 1433,
|
||||
database: process.env.DB_DATABASE,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
options: {
|
||||
encrypt: process.env.DB_ENCRYPT === 'true',
|
||||
trustServerCertificate: process.env.DB_TRUST_SERVER_CERTIFICATE === 'true',
|
||||
enableArithAbort: true,
|
||||
connectionTimeout: 30000,
|
||||
requestTimeout: 30000
|
||||
},
|
||||
pool: {
|
||||
max: 10,
|
||||
min: 0,
|
||||
idleTimeoutMillis: 30000
|
||||
}
|
||||
};
|
||||
|
||||
let pool = null;
|
||||
|
||||
const getConnection = async () => {
|
||||
if (!pool) {
|
||||
pool = await sql.connect(config);
|
||||
}
|
||||
return pool;
|
||||
};
|
||||
|
||||
const closeConnection = async () => {
|
||||
if (pool) {
|
||||
await pool.close();
|
||||
pool = null;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
sql,
|
||||
getConnection,
|
||||
closeConnection,
|
||||
config
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user