Skip to content

Commit 98ce9eb

Browse files
committed
Modified to only show the list of DB names actually used in the work query statement.
1 parent acfcd03 commit 98ce9eb

File tree

2 files changed

+151
-10
lines changed

2 files changed

+151
-10
lines changed

queries/queries-with-template.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<queries>
2+
<excel db="sampleDB" output="d:/temp/sales_summary_template_2024.xlsx" maxRows="20" style="business">
3+
<!-- Global style template ID (default: default) -->
4+
<!-- Individual styles can be specified per sheet -->
5+
<!-- Available templates: default, modern, dark, colorful, minimal, business, premium -->
6+
</excel>
7+
<vars>
8+
<var name="envType">Production</var>
9+
<var name="startDate">2024-01-01</var>
10+
<var name="endDate">2024-06-30</var>
11+
<var name="regionList">["Seoul", "Busan"]</var>
12+
<var name="statusList">["ACTIVE", "PENDING", "COMPLETED"]</var>
13+
<var name="categoryIds">[1, 2, 3, 5]</var>
14+
<var name="maxRows">1000</var>
15+
</vars>
16+
<sheet name="${envType}_Order_List" use="true" aggregateColumn="PaymentMethod" maxRows="10" db="sampleDB" style="modern">
17+
<!-- Sheet-specific style: modern -->
18+
<![CDATA[
19+
SELECT
20+
OrderNumber as OrderNumber,
21+
FORMAT(OrderDate, 'yyyy-MM-dd') as OrderDate,
22+
OrderStatus as OrderStatus,
23+
PaymentStatus as PaymentStatus,
24+
FORMAT(TotalAmount, 'N0') as TotalAmount,
25+
PaymentMethod as PaymentMethod
26+
FROM SampleDB.dbo.Orders
27+
WHERE OrderDate >= '${startDate}' AND OrderDate <= '${endDate}'
28+
ORDER BY OrderDate DESC
29+
]]>
30+
</sheet>
31+
<sheet name="Customer_List" use="true" aggregateColumn="Region">
32+
<!-- No sheet-specific style: uses global style (business) -->
33+
<![CDATA[
34+
SELECT
35+
CustomerCode as CustomerCode,
36+
CustomerName as CustomerName,
37+
ContactName as ContactName,
38+
City as City,
39+
Region as Region,
40+
CustomerType as CustomerType,
41+
FORMAT(CreditLimit, 'N0') as CreditLimit
42+
FROM SampleDB.dbo.Customers
43+
WHERE Region IN (${regionList}) AND IsActive = 1
44+
ORDER BY CreditLimit DESC
45+
]]>
46+
</sheet>
47+
<sheet name="Product_List" use="true" aggregateColumn="Category" style="colorful">
48+
<!-- Sheet-specific style: colorful -->
49+
<![CDATA[
50+
SELECT
51+
ProductID as ProductID,
52+
ProductName as ProductName,
53+
CategoryName as Category,
54+
FORMAT(UnitPrice, 'N0') as UnitPrice,
55+
UnitsInStock as UnitsInStock,
56+
Discontinued as Discontinued
57+
FROM SampleDB.dbo.Products p
58+
INNER JOIN SampleDB.dbo.Categories c ON p.CategoryID = c.CategoryID
59+
WHERE p.CategoryID IN (${categoryIds})
60+
ORDER BY c.CategoryName, p.ProductName
61+
]]>
62+
</sheet>
63+
</queries>
64+

src/excel-cli.js

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,94 @@ async function validateQueryFile(options) {
439439
console.log('\n✅ 데이터베이스 설정 로드');
440440
console.log(` 설정된 DB 개수: ${Object.keys(databases).length}개`);
441441

442-
// 데이터베이스 목록 출력
443-
console.log('\n📋 데이터베이스 목록:');
444-
for (const [dbId, dbConfig] of Object.entries(databases)) {
445-
console.log(` ✅ ${dbId}:`);
446-
console.log(` 서버: ${dbConfig.server}`);
447-
console.log(` 데이터베이스: ${dbConfig.database}`);
448-
console.log(` 사용자: ${dbConfig.user}`);
449-
console.log(` 쓰기 권한: ${dbConfig.isWritable ? '있음' : '없음'}`);
450-
if (dbConfig.description) {
451-
console.log(` 설명: ${dbConfig.description}`);
442+
// 쿼리 파일에서 사용되는 DB 수집
443+
const usedDatabases = new Set();
444+
445+
if (fileType === 'XML') {
446+
const xml2js = require('xml2js');
447+
const parsed = await xml2js.parseStringPromise(fileContent, { trim: true });
448+
449+
// excel 태그의 db 속성 확인
450+
if (parsed.queries.excel && parsed.queries.excel[0] && parsed.queries.excel[0].$ && parsed.queries.excel[0].$.db) {
451+
usedDatabases.add(parsed.queries.excel[0].$.db);
452+
}
453+
454+
// 각 시트의 db 속성 확인
455+
const sheets = Array.isArray(parsed.queries.sheet) ? parsed.queries.sheet : [parsed.queries.sheet];
456+
for (const sheet of sheets) {
457+
if (sheet.$ && sheet.$.db) {
458+
usedDatabases.add(sheet.$.db);
459+
}
460+
}
461+
462+
// dynamicVars의 database 속성 확인
463+
if (parsed.queries.dynamicVars && parsed.queries.dynamicVars[0] && parsed.queries.dynamicVars[0].dynamicVar) {
464+
const dynamicVars = Array.isArray(parsed.queries.dynamicVars[0].dynamicVar)
465+
? parsed.queries.dynamicVars[0].dynamicVar
466+
: [parsed.queries.dynamicVars[0].dynamicVar];
467+
for (const dv of dynamicVars) {
468+
if (dv.$ && dv.$.database) {
469+
usedDatabases.add(dv.$.database);
470+
}
471+
}
472+
}
473+
} else if (fileType === 'JSON') {
474+
const JSON5 = require('json5');
475+
const parsed = JSON5.parse(fileContent);
476+
477+
// excel.db 확인
478+
if (parsed.excel && parsed.excel.db) {
479+
usedDatabases.add(parsed.excel.db);
452480
}
481+
482+
// 각 시트의 db 확인
483+
if (parsed.sheets) {
484+
for (const sheet of parsed.sheets) {
485+
if (sheet.db) {
486+
usedDatabases.add(sheet.db);
487+
}
488+
}
489+
}
490+
491+
// dynamicVars의 database 확인
492+
if (parsed.dynamicVars) {
493+
for (const dv of parsed.dynamicVars) {
494+
if (dv.database) {
495+
usedDatabases.add(dv.database);
496+
}
497+
}
498+
}
499+
}
500+
501+
// 사용되는 데이터베이스 목록만 출력
502+
let dbValidationErrors = false;
503+
if (usedDatabases.size > 0) {
504+
console.log(`\n📋 이 쿼리 파일에서 사용하는 데이터베이스 (${usedDatabases.size}개):`);
505+
for (const dbId of usedDatabases) {
506+
if (databases[dbId]) {
507+
const dbConfig = databases[dbId];
508+
console.log(` ✅ ${dbId}:`);
509+
console.log(` 서버: ${dbConfig.server}`);
510+
console.log(` 데이터베이스: ${dbConfig.database}`);
511+
console.log(` 사용자: ${dbConfig.user}`);
512+
console.log(` 쓰기 권한: ${dbConfig.isWritable ? '있음' : '없음'}`);
513+
if (dbConfig.description) {
514+
console.log(` 설명: ${dbConfig.description}`);
515+
}
516+
} else {
517+
console.error(` ❌ ${dbId}: 설정 파일에서 찾을 수 없습니다.`);
518+
dbValidationErrors = true;
519+
}
520+
}
521+
} else {
522+
console.log('\n📋 데이터베이스 사용 정보:');
523+
console.log(' ℹ️ 쿼리 파일에서 명시적으로 지정된 DB가 없습니다.');
524+
console.log(' 💡 기본 DB가 사용됩니다.');
525+
}
526+
527+
if (dbValidationErrors) {
528+
console.error('\n❌ 검증 실패: 설정 파일에서 찾을 수 없는 DB가 있습니다.');
529+
return false;
453530
}
454531

455532
console.log('\n✅ 모든 검증이 완료되었습니다.');

0 commit comments

Comments
 (0)