60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
|
|
const oracledb = require('oracledb');
|
||
|
|
const dbConfig = require('../config/database');
|
||
|
|
|
||
|
|
// Oracle Client 초기화 (Thick mode)
|
||
|
|
try {
|
||
|
|
oracledb.initOracleClient();
|
||
|
|
} catch (err) {
|
||
|
|
console.error('Oracle Client 초기화 실패:', err);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 연결 풀 설정
|
||
|
|
const poolConfig = {
|
||
|
|
user: dbConfig.username,
|
||
|
|
password: dbConfig.password,
|
||
|
|
connectString: dbConfig.connectString,
|
||
|
|
poolMin: 2,
|
||
|
|
poolMax: 10,
|
||
|
|
poolIncrement: 1,
|
||
|
|
poolTimeout: 300
|
||
|
|
};
|
||
|
|
|
||
|
|
let pool;
|
||
|
|
|
||
|
|
async function initializePool() {
|
||
|
|
try {
|
||
|
|
pool = await oracledb.createPool(poolConfig);
|
||
|
|
console.log('Oracle DB 연결 풀이 생성되었습니다.');
|
||
|
|
} catch (err) {
|
||
|
|
console.error('DB 연결 풀 생성 실패:', err);
|
||
|
|
throw err;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function getConnection() {
|
||
|
|
try {
|
||
|
|
const connection = await pool.getConnection();
|
||
|
|
return connection;
|
||
|
|
} catch (err) {
|
||
|
|
console.error('DB 연결 실패:', err);
|
||
|
|
throw err;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function closePool() {
|
||
|
|
try {
|
||
|
|
if (pool) {
|
||
|
|
await pool.close();
|
||
|
|
console.log('Oracle DB 연결 풀이 종료되었습니다.');
|
||
|
|
}
|
||
|
|
} catch (err) {
|
||
|
|
console.error('DB 연결 풀 종료 실패:', err);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = {
|
||
|
|
initializePool,
|
||
|
|
getConnection,
|
||
|
|
closePool
|
||
|
|
};
|