155 lines
3.7 KiB
TypeScript
155 lines
3.7 KiB
TypeScript
/**
|
|
* 다중 커넥션 관리 API 클라이언트
|
|
*/
|
|
|
|
import { apiClient } from "./client";
|
|
|
|
export interface MultiConnectionTableInfo {
|
|
tableName: string;
|
|
displayName?: string;
|
|
columnCount: number;
|
|
connectionId: number;
|
|
connectionName: string;
|
|
dbType: string;
|
|
}
|
|
|
|
export interface ColumnInfo {
|
|
columnName: string;
|
|
displayName: string;
|
|
dataType: string;
|
|
dbType: string;
|
|
webType: string;
|
|
isNullable: boolean;
|
|
isPrimaryKey: boolean;
|
|
defaultValue?: string;
|
|
maxLength?: number;
|
|
description?: string;
|
|
}
|
|
|
|
export interface ConnectionInfo {
|
|
id: number;
|
|
connection_name: string;
|
|
description?: string;
|
|
db_type: string;
|
|
host: string;
|
|
port: number;
|
|
database_name: string;
|
|
username: string;
|
|
is_active: string;
|
|
company_code: string;
|
|
created_date: Date;
|
|
updated_date: Date;
|
|
}
|
|
|
|
export interface ValidationResult {
|
|
isValid: boolean;
|
|
error?: string;
|
|
warnings?: string[];
|
|
}
|
|
|
|
/**
|
|
* 제어관리용 활성 커넥션 목록 조회 (메인 DB 포함)
|
|
*/
|
|
export const getActiveConnections = async (): Promise<ConnectionInfo[]> => {
|
|
const response = await apiClient.get("/external-db-connections/control/active");
|
|
return response.data.data || [];
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션의 테이블 목록 조회
|
|
*/
|
|
export const getTablesFromConnection = async (connectionId: number): Promise<MultiConnectionTableInfo[]> => {
|
|
const response = await apiClient.get(`/multi-connection/connections/${connectionId}/tables`);
|
|
return response.data.data || [];
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션의 테이블 컬럼 정보 조회
|
|
*/
|
|
export const getColumnsFromConnection = async (connectionId: number, tableName: string): Promise<ColumnInfo[]> => {
|
|
const response = await apiClient.get(`/multi-connection/connections/${connectionId}/tables/${tableName}/columns`);
|
|
return response.data.data || [];
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션에서 데이터 조회
|
|
*/
|
|
export const queryDataFromConnection = async (
|
|
connectionId: number,
|
|
tableName: string,
|
|
conditions?: Record<string, any>,
|
|
): Promise<Record<string, any>[]> => {
|
|
const response = await apiClient.post(`/multi-connection/connections/${connectionId}/query`, {
|
|
tableName,
|
|
conditions,
|
|
});
|
|
return response.data.data || [];
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션에 데이터 삽입
|
|
*/
|
|
export const insertDataToConnection = async (
|
|
connectionId: number,
|
|
tableName: string,
|
|
data: Record<string, any>,
|
|
): Promise<any> => {
|
|
const response = await apiClient.post(`/multi-connection/connections/${connectionId}/insert`, {
|
|
tableName,
|
|
data,
|
|
});
|
|
return response.data.data || {};
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션의 데이터 업데이트
|
|
*/
|
|
export const updateDataInConnection = async (
|
|
connectionId: number,
|
|
tableName: string,
|
|
data: Record<string, any>,
|
|
conditions: Record<string, any>,
|
|
): Promise<any> => {
|
|
const response = await apiClient.put(`/multi-connection/connections/${connectionId}/update`, {
|
|
tableName,
|
|
data,
|
|
conditions,
|
|
});
|
|
return response.data.data || {};
|
|
};
|
|
|
|
/**
|
|
* 특정 커넥션에서 데이터 삭제
|
|
*/
|
|
export const deleteDataFromConnection = async (
|
|
connectionId: number,
|
|
tableName: string,
|
|
conditions: Record<string, any>,
|
|
maxDeleteCount?: number,
|
|
): Promise<any> => {
|
|
const response = await apiClient.delete(`/multi-connection/connections/${connectionId}/delete`, {
|
|
data: {
|
|
tableName,
|
|
conditions,
|
|
maxDeleteCount,
|
|
},
|
|
});
|
|
return response.data.data || {};
|
|
};
|
|
|
|
/**
|
|
* 자기 자신 테이블 작업 검증
|
|
*/
|
|
export const validateSelfTableOperation = async (
|
|
tableName: string,
|
|
operation: "update" | "delete",
|
|
conditions: any[],
|
|
): Promise<ValidationResult> => {
|
|
const response = await apiClient.post("/multi-connection/validate-self-operation", {
|
|
tableName,
|
|
operation,
|
|
conditions,
|
|
});
|
|
return response.data.data || {};
|
|
};
|