Skip to content

Commit 7a27d6c

Browse files
committed
Added improvement
1. Remove dbs wrapper from dbinfo.js and fix related logic 2. Exclude internal keys (such as $, _) used by xml2js from validation when parsing XML.
1 parent 7f50b86 commit 7a27d6c

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

config/dbinfo.json

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
{
2-
"dbs": {
3-
"sampleDB": {
4-
"user": "sample",
5-
"password": "sample1234!",
6-
"server": "localhost",
7-
"database": "SampleDB",
8-
"port": 1433,
9-
"options": { "encrypt": true, "trustServerCertificate": true }
10-
},
11-
"erpDB": {
12-
"user": "erp",
13-
"password": "erp1234!",
14-
"server": "localhost",
15-
"database": "ERP_DB",
16-
"port": 1433,
17-
"options": { "encrypt": true, "trustServerCertificate": true }
18-
},
19-
"sourceDB": {
20-
"user": "sample",
21-
"password": "sample1234!",
22-
"server": "localhost",
23-
"database": "sourceDB",
24-
"port": 1433,
25-
"isWritable": false,
26-
"description": "운영 환경 소스 데이터베이스 (읽기 전용)",
27-
"options": {
28-
"encrypt": true,
29-
"trustServerCertificate": true,
30-
"enableArithAbort": true,
31-
"requestTimeout": 300000,
32-
"connectionTimeout": 30000
33-
}
2+
"sampleDB": {
3+
"user": "sample",
4+
"password": "sample1234!",
5+
"server": "localhost",
6+
"database": "SampleDB",
7+
"port": 1433,
8+
"options": { "encrypt": true, "trustServerCertificate": true }
9+
},
10+
"erpDB": {
11+
"user": "erp",
12+
"password": "erp1234!",
13+
"server": "localhost",
14+
"database": "ERP_DB",
15+
"port": 1433,
16+
"options": { "encrypt": true, "trustServerCertificate": true }
17+
},
18+
"sourceDB": {
19+
"user": "sample",
20+
"password": "sample1234!",
21+
"server": "localhost",
22+
"database": "sourceDB",
23+
"port": 1433,
24+
"isWritable": false,
25+
"description": "운영 환경 소스 데이터베이스 (읽기 전용)",
26+
"options": {
27+
"encrypt": true,
28+
"trustServerCertificate": true,
29+
"enableArithAbort": true,
30+
"requestTimeout": 300000,
31+
"connectionTimeout": 30000
3432
}
3533
}
3634
}

src/excel-cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ function loadDatabaseConfig(configPath) {
138138
const configData = fs.readFileSync(configPath, 'utf8');
139139
const config = JSON.parse(configData);
140140

141-
if (!config.dbs || typeof config.dbs !== 'object') {
142-
throw new Error('설정 파일에 dbs 섹션이 없거나 올바르지 않습니다.');
141+
if (typeof config !== 'object' || !config) {
142+
throw new Error('설정 파일 형식이 올바르지 않습니다.');
143143
}
144144

145-
return config.dbs;
145+
return config;
146146
} catch (error) {
147147
throw new Error(`설정 파일 로드 실패: ${error.message}`);
148148
}

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,21 @@ async function main() {
141141
const mssqlHelper = new MSSQLHelper();
142142

143143
// 연결 설정 검증
144-
for (const [dbKey, config] of Object.entries(configObj.dbs || {})) {
144+
for (const [dbKey, config] of Object.entries(configObj || {})) {
145145
if (!mssqlHelper.validateConnectionConfig(config)) {
146146
throw new Error(`DB 연결 설정이 올바르지 않습니다: ${dbKey} (필수 필드: server, database, user, password)`);
147147
}
148148
}
149149

150150
// 기본 DB 연결 설정
151151
const defaultDbKey = argv.db || dbId || excelDb;
152-
if (!configObj.dbs || !configObj.dbs[defaultDbKey]) {
152+
if (!configObj || !configObj[defaultDbKey]) {
153153
throw new Error(`기본 DB 접속 ID를 찾을 수 없습니다: ${defaultDbKey}`);
154154
}
155155

156156
// DB 연결 풀 생성 함수
157157
async function getDbPool(dbKey) {
158-
return await mssqlHelper.createConnectionPool(configObj.dbs[dbKey], dbKey);
158+
return await mssqlHelper.createConnectionPool(configObj[dbKey], dbKey);
159159
}
160160

161161
// 기본 DB 연결

src/query-parser.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,18 @@ class QueryParser {
9898
if (parsed.queries) {
9999
const queries = parsed.queries;
100100
const queryKeys = Object.keys(queries);
101-
const invalidElements = queryKeys.filter(key => !allowedElements.queries.includes(key));
101+
// xml2js 내부 키 제외 ($, _ 등)
102+
const xml2jsInternalKeys = ['$', '_', '#text', '__text', '__cdata', 'cdata', '#cdata-section', '$text', '$value', 'value'];
103+
const actualElements = queryKeys.filter(key => !xml2jsInternalKeys.includes(key));
104+
const invalidElements = actualElements.filter(key => !allowedElements.queries.includes(key));
102105
if (invalidElements.length > 0) {
106+
console.error(`\n[DEBUG] queries 객체의 모든 키:`, queryKeys);
107+
console.error(`[DEBUG] xml2js 내부 키 제외 후:`, actualElements);
108+
console.error(`[DEBUG] 허용되는 element:`, allowedElements.queries);
109+
console.error(`[DEBUG] 잘못된 element:`, invalidElements);
103110
errors.push(`queries 내 허용되지 않는 element: ${invalidElements.join(', ')}`);
111+
errors.push(` 허용되는 element: ${allowedElements.queries.join(', ')}`);
112+
errors.push(` 발견된 실제 element: ${actualElements.join(', ')}`);
104113
}
105114

106115
// excel element 속성 검증

src/variable-processor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class VariableProcessor {
4747
console.log(` 데이터베이스: ${targetDbKey} (${dynamicVar.database ? '동적변수 지정' : '기본값'})`);
4848

4949
// DB에서 데이터 조회
50-
const pool = await mssqlHelper.createConnectionPool(configObj.dbs[targetDbKey], targetDbKey);
50+
const pool = await mssqlHelper.createConnectionPool(configObj[targetDbKey], targetDbKey);
5151
const result = await mssqlHelper.executeQuery(pool, processedQuery);
5252

5353
if (result.recordset && result.recordset.length > 0) {

0 commit comments

Comments
 (0)