내부 db로만 요청이 보내지는 현상 수정
This commit is contained in:
parent
f040e8eb35
commit
60090873b3
|
|
@ -252,26 +252,51 @@ export function CanvasElement({
|
||||||
|
|
||||||
setIsLoadingData(true);
|
setIsLoadingData(true);
|
||||||
try {
|
try {
|
||||||
// console.log('🔄 쿼리 실행 시작:', element.dataSource.query);
|
let result;
|
||||||
|
|
||||||
// 실제 API 호출
|
// 외부 DB vs 현재 DB 분기
|
||||||
const { dashboardApi } = await import("@/lib/api/dashboard");
|
if (element.dataSource.connectionType === "external" && element.dataSource.externalConnectionId) {
|
||||||
const result = await dashboardApi.executeQuery(element.dataSource.query);
|
// 외부 DB
|
||||||
|
const { ExternalDbConnectionAPI } = await import("@/lib/api/externalDbConnection");
|
||||||
|
const externalResult = await ExternalDbConnectionAPI.executeQuery(
|
||||||
|
parseInt(element.dataSource.externalConnectionId),
|
||||||
|
element.dataSource.query,
|
||||||
|
);
|
||||||
|
|
||||||
// console.log('✅ 쿼리 실행 결과:', result);
|
if (!externalResult.success) {
|
||||||
|
throw new Error(externalResult.message || "외부 DB 쿼리 실행 실패");
|
||||||
|
}
|
||||||
|
|
||||||
setChartData({
|
setChartData({
|
||||||
columns: result.columns || [],
|
columns: externalResult.data?.[0] ? Object.keys(externalResult.data[0]) : [],
|
||||||
rows: result.rows || [],
|
rows: externalResult.data || [],
|
||||||
totalRows: result.rowCount || 0,
|
totalRows: externalResult.data?.length || 0,
|
||||||
executionTime: 0,
|
executionTime: 0,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// 현재 DB
|
||||||
|
const { dashboardApi } = await import("@/lib/api/dashboard");
|
||||||
|
result = await dashboardApi.executeQuery(element.dataSource.query);
|
||||||
|
|
||||||
|
setChartData({
|
||||||
|
columns: result.columns || [],
|
||||||
|
rows: result.rows || [],
|
||||||
|
totalRows: result.rowCount || 0,
|
||||||
|
executionTime: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error("Chart data loading error:", error);
|
||||||
setChartData(null);
|
setChartData(null);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingData(false);
|
setIsLoadingData(false);
|
||||||
}
|
}
|
||||||
}, [element.dataSource?.query, element.type]);
|
}, [
|
||||||
|
element.dataSource?.query,
|
||||||
|
element.dataSource?.connectionType,
|
||||||
|
element.dataSource?.externalConnectionId,
|
||||||
|
element.type,
|
||||||
|
]);
|
||||||
|
|
||||||
// 컴포넌트 마운트 시 및 쿼리 변경 시 데이터 로딩
|
// 컴포넌트 마운트 시 및 쿼리 변경 시 데이터 로딩
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue