From 217e215e5487b53db7d64fe3d809c47289cd83ae Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 28 May 2025 00:30:18 +0000 Subject: (김준회) 오라클 DB 연결을 위한 처리 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/oracle-db/db.ts | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lib/oracle-db/db.ts (limited to 'lib/oracle-db/db.ts') diff --git a/lib/oracle-db/db.ts b/lib/oracle-db/db.ts new file mode 100644 index 00000000..62321df0 --- /dev/null +++ b/lib/oracle-db/db.ts @@ -0,0 +1,69 @@ +import knex from 'knex'; +// import oracledb from 'oracledb'; +// eslint-disable-next-line @typescript-eslint/no-require-imports +const oracledb = require('oracledb'); + +// Knex Oracle 연결 생성 +export const oracleKnex = knex({ + client: 'oracledb', + connection: { + user: process.env.ORACLE_USER, + password: process.env.ORACLE_PASSWORD, + connectString: process.env.ORACLE_CONNECTION_STRING, + }, + pool: { min: 0, max: 5 } +}); + +// OracleDB 직접 연결 생성 함수 +export async function getOracleConnection() { + try { + const connection = await oracledb.getConnection({ + user: process.env.ORACLE_USER, + password: process.env.ORACLE_PASSWORD, + connectString: process.env.ORACLE_CONNECTION_STRING + }); + + return connection; + } catch (error) { + console.error('Oracle DB 연결 오류:', error); + throw error; + } +} + +// 연결을 테스트하는 함수 +export async function testOracleConnection() { + try { + const connection = await getOracleConnection(); + const result = await connection.execute('SELECT 1 FROM DUAL'); + await connection.close(); + return { + success: true, + message: 'Oracle DB 연결 성공', + data: result.rows + }; + } catch (error: unknown) { + return { + success: false, + message: 'Oracle DB 연결 실패', + error: error instanceof Error ? error.message : '알 수 없는 오류' + }; + } +} + +// Knex를 사용하여 Oracle 연결 테스트 +export async function testKnexOracleConnection() { + try { + const result = await oracleKnex.raw('SELECT 1 FROM DUAL'); + return { + success: true, + message: 'Knex Oracle DB 연결 성공', + data: result + }; + } catch (error: unknown) { + return { + success: false, + message: 'Knex Oracle DB 연결 실패', + error: error instanceof Error ? error.message : '알 수 없는 오류' + }; + } +} \ No newline at end of file -- cgit v1.2.3