diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-28 00:30:18 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-28 00:30:18 +0000 |
| commit | 217e215e5487b53db7d64fe3d809c47289cd83ae (patch) | |
| tree | acead961488299e640f73365ccd4949f9a002ab3 /lib/oracle-knex | |
| parent | 1d86653b12ec52cd6ba4b92a7b6a841506a190c5 (diff) | |
(김준회) 오라클 DB 연결을 위한 처리
Diffstat (limited to 'lib/oracle-knex')
| -rw-r--r-- | lib/oracle-knex/README.md | 54 | ||||
| -rw-r--r-- | lib/oracle-knex/db.ts | 68 |
2 files changed, 0 insertions, 122 deletions
diff --git a/lib/oracle-knex/README.md b/lib/oracle-knex/README.md deleted file mode 100644 index fdff6e2f..00000000 --- a/lib/oracle-knex/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# oracledb / knex.js 사용 방법 - -1. oracledb로 SQL 직접 사용하기 - -```ts - // Oracle DB 연결 설정 - const connection = await oracledb.getConnection({ - user: process.env.ORACLE_USER, - password: process.env.ORACLE_PASSWORD, - connectString: process.env.ORACLE_CONNECTION_STRING - - }); - - // 쿼리 수행 - const result = await connection.execute('SELECT 1 FROM DUAL'); - - // 연결 종료 - await connection.close(); -``` - -2. knex.js에서 SQL 직접 사용하기 - -```ts -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 } -}); - -sql = 'SELECT 1 FROM DUAL;' -const result = await oracleKnex.raw(sql); -``` - -3. knex.js에서 쿼리빌더 사용하기 -```ts -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 } -}); - -const result = await knex -.qb -.select('column1', 'column2', 'column3') -.from('table_name') -```
\ No newline at end of file diff --git a/lib/oracle-knex/db.ts b/lib/oracle-knex/db.ts deleted file mode 100644 index fe61f0a2..00000000 --- a/lib/oracle-knex/db.ts +++ /dev/null @@ -1,68 +0,0 @@ -import knex from 'knex'; -// import oracledb from 'oracledb'; -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: any) { - 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: any) { - return { - success: false, - message: 'Knex Oracle DB 연결 실패', - error: error instanceof Error ? error.message : '알 수 없는 오류' - }; - } -}
\ No newline at end of file |
