스크롤 기능 포함
This commit is contained in:
52
backend-node/src/database/DatabaseConnectorFactory.ts
Normal file
52
backend-node/src/database/DatabaseConnectorFactory.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { DatabaseConnector, ConnectionConfig } from '../interfaces/DatabaseConnector';
|
||||
import { PostgreSQLConnector } from './PostgreSQLConnector';
|
||||
|
||||
export class DatabaseConnectorFactory {
|
||||
private static connectors = new Map<string, DatabaseConnector>();
|
||||
|
||||
static async createConnector(
|
||||
type: string,
|
||||
config: ConnectionConfig,
|
||||
connectionId: number // Added connectionId for unique key
|
||||
): Promise<DatabaseConnector> {
|
||||
const key = `${type}-${connectionId}`; // Use connectionId for unique key
|
||||
if (this.connectors.has(key)) {
|
||||
return this.connectors.get(key)!;
|
||||
}
|
||||
|
||||
let connector: DatabaseConnector;
|
||||
|
||||
switch (type.toLowerCase()) {
|
||||
case 'postgresql':
|
||||
connector = new PostgreSQLConnector(config);
|
||||
break;
|
||||
// Add other database types here
|
||||
default:
|
||||
throw new Error(`지원하지 않는 데이터베이스 타입: ${type}`);
|
||||
}
|
||||
|
||||
this.connectors.set(key, connector);
|
||||
return connector;
|
||||
}
|
||||
|
||||
static async getConnector(connectionId: number, type: string): Promise<DatabaseConnector | undefined> {
|
||||
const key = `${type}-${connectionId}`;
|
||||
return this.connectors.get(key);
|
||||
}
|
||||
|
||||
static async closeConnector(connectionId: number, type: string): Promise<void> {
|
||||
const key = `${type}-${connectionId}`;
|
||||
const connector = this.connectors.get(key);
|
||||
if (connector) {
|
||||
await connector.disconnect();
|
||||
this.connectors.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
static async closeAll(): Promise<void> {
|
||||
for (const connector of this.connectors.values()) {
|
||||
await connector.disconnect();
|
||||
}
|
||||
this.connectors.clear();
|
||||
}
|
||||
}
|
||||
175
backend-node/src/database/MySQLConnector.ts
Normal file
175
backend-node/src/database/MySQLConnector.ts
Normal file
@@ -0,0 +1,175 @@
|
||||
import * as mysql from 'mysql2/promise';
|
||||
import { DatabaseConnector, ConnectionConfig, QueryResult } from '../interfaces/DatabaseConnector';
|
||||
import { ConnectionTestResult, TableInfo } from '../types/externalDbTypes';
|
||||
|
||||
export class MySQLConnector implements DatabaseConnector {
|
||||
private connection: mysql.Connection | null = null;
|
||||
private config: ConnectionConfig;
|
||||
|
||||
constructor(config: ConnectionConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if (this.connection) {
|
||||
throw new Error('이미 연결되어 있습니다.');
|
||||
}
|
||||
|
||||
this.connection = await mysql.createConnection({
|
||||
host: this.config.host,
|
||||
port: this.config.port,
|
||||
database: this.config.database,
|
||||
user: this.config.username,
|
||||
password: this.config.password,
|
||||
connectTimeout: this.config.connectionTimeout || 30000,
|
||||
ssl: this.config.sslEnabled ? { rejectUnauthorized: false } : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (this.connection) {
|
||||
await this.connection.end();
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
async testConnection(): Promise<ConnectionTestResult> {
|
||||
const startTime = Date.now();
|
||||
try {
|
||||
await this.connect();
|
||||
|
||||
const [versionResult] = await this.connection!.query('SELECT VERSION() as version');
|
||||
const [sizeResult] = await this.connection!.query(
|
||||
'SELECT SUM(data_length + index_length) as size FROM information_schema.tables WHERE table_schema = DATABASE()'
|
||||
);
|
||||
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'MySQL 연결이 성공했습니다.',
|
||||
details: {
|
||||
response_time: responseTime,
|
||||
server_version: (versionResult as any)[0]?.version || '알 수 없음',
|
||||
database_size: this.formatBytes(parseInt((sizeResult as any)[0]?.size || '0')),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'MySQL 연결에 실패했습니다.',
|
||||
error: {
|
||||
code: 'CONNECTION_FAILED',
|
||||
details: error instanceof Error ? error.message : '알 수 없는 오류',
|
||||
},
|
||||
};
|
||||
} finally {
|
||||
await this.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
async executeQuery(query: string): Promise<QueryResult> {
|
||||
if (!this.connection) {
|
||||
await this.connect();
|
||||
}
|
||||
|
||||
try {
|
||||
const [rows, fields] = await this.connection!.query(query);
|
||||
return {
|
||||
rows: rows as any[],
|
||||
rowCount: Array.isArray(rows) ? rows.length : 0,
|
||||
fields: (fields as mysql.FieldPacket[]).map(field => ({
|
||||
name: field.name,
|
||||
dataType: field.type.toString(),
|
||||
})),
|
||||
};
|
||||
} finally {
|
||||
await this.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
async getTables(): Promise<TableInfo[]> {
|
||||
if (!this.connection) {
|
||||
await this.connect();
|
||||
}
|
||||
|
||||
try {
|
||||
const [tables] = await this.connection!.query(`
|
||||
SELECT
|
||||
t.TABLE_NAME as table_name,
|
||||
t.TABLE_COMMENT as table_description
|
||||
FROM information_schema.TABLES t
|
||||
WHERE t.TABLE_SCHEMA = DATABASE()
|
||||
ORDER BY t.TABLE_NAME
|
||||
`);
|
||||
|
||||
const result: TableInfo[] = [];
|
||||
|
||||
for (const table of tables as any[]) {
|
||||
const [columns] = await this.connection!.query(`
|
||||
SELECT
|
||||
COLUMN_NAME as column_name,
|
||||
DATA_TYPE as data_type,
|
||||
IS_NULLABLE as is_nullable,
|
||||
COLUMN_DEFAULT as column_default
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = ?
|
||||
ORDER BY ORDINAL_POSITION
|
||||
`, [table.table_name]);
|
||||
|
||||
result.push({
|
||||
table_name: table.table_name,
|
||||
description: table.table_description || null,
|
||||
columns: columns as any[],
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
} finally {
|
||||
await this.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
async getColumns(tableName: string): Promise<Array<{
|
||||
name: string;
|
||||
dataType: string;
|
||||
isNullable: boolean;
|
||||
defaultValue?: string;
|
||||
}>> {
|
||||
if (!this.connection) {
|
||||
await this.connect();
|
||||
}
|
||||
|
||||
try {
|
||||
const [columns] = await this.connection!.query(`
|
||||
SELECT
|
||||
COLUMN_NAME as name,
|
||||
DATA_TYPE as dataType,
|
||||
IS_NULLABLE = 'YES' as isNullable,
|
||||
COLUMN_DEFAULT as defaultValue
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = ?
|
||||
ORDER BY ORDINAL_POSITION
|
||||
`, [tableName]);
|
||||
|
||||
return (columns as any[]).map(col => ({
|
||||
name: col.name,
|
||||
dataType: col.dataType,
|
||||
isNullable: col.isNullable,
|
||||
defaultValue: col.defaultValue,
|
||||
}));
|
||||
} finally {
|
||||
await this.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
}
|
||||
}
|
||||
145
backend-node/src/database/PostgreSQLConnector.ts
Normal file
145
backend-node/src/database/PostgreSQLConnector.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
import { Client } from 'pg';
|
||||
import { DatabaseConnector, ConnectionConfig, QueryResult } from '../interfaces/DatabaseConnector';
|
||||
import { ConnectionTestResult, TableInfo } from '../types/externalDbTypes';
|
||||
|
||||
export class PostgreSQLConnector implements DatabaseConnector {
|
||||
private client: Client | null = null;
|
||||
private config: ConnectionConfig;
|
||||
|
||||
constructor(config: ConnectionConfig) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
if (this.client) {
|
||||
await this.disconnect();
|
||||
}
|
||||
const clientConfig: any = {
|
||||
host: this.config.host,
|
||||
port: this.config.port,
|
||||
database: this.config.database,
|
||||
user: this.config.user,
|
||||
password: this.config.password,
|
||||
};
|
||||
|
||||
if (this.config.connectionTimeoutMillis != null) {
|
||||
clientConfig.connectionTimeoutMillis = this.config.connectionTimeoutMillis;
|
||||
}
|
||||
|
||||
if (this.config.queryTimeoutMillis != null) {
|
||||
clientConfig.query_timeout = this.config.queryTimeoutMillis;
|
||||
}
|
||||
|
||||
if (this.config.ssl != null) {
|
||||
clientConfig.ssl = this.config.ssl;
|
||||
}
|
||||
|
||||
this.client = new Client(clientConfig);
|
||||
await this.client.connect();
|
||||
}
|
||||
|
||||
async disconnect(): Promise<void> {
|
||||
if (this.client) {
|
||||
await this.client.end();
|
||||
this.client = null;
|
||||
}
|
||||
}
|
||||
|
||||
async testConnection(): Promise<ConnectionTestResult> {
|
||||
const startTime = Date.now();
|
||||
try {
|
||||
await this.connect();
|
||||
const result = await this.client!.query("SELECT version(), pg_database_size(current_database()) as size");
|
||||
const responseTime = Date.now() - startTime;
|
||||
await this.disconnect();
|
||||
return {
|
||||
success: true,
|
||||
message: "PostgreSQL 연결이 성공했습니다.",
|
||||
details: {
|
||||
response_time: responseTime,
|
||||
server_version: result.rows[0]?.version || "알 수 없음",
|
||||
database_size: this.formatBytes(parseInt(result.rows[0]?.size || "0")),
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
await this.disconnect();
|
||||
return {
|
||||
success: false,
|
||||
message: "PostgreSQL 연결에 실패했습니다.",
|
||||
error: {
|
||||
code: "CONNECTION_FAILED",
|
||||
details: error.message || "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async executeQuery(query: string): Promise<QueryResult> {
|
||||
try {
|
||||
await this.connect();
|
||||
const result = await this.client!.query(query);
|
||||
await this.disconnect();
|
||||
return {
|
||||
rows: result.rows,
|
||||
rowCount: result.rowCount ?? undefined,
|
||||
fields: result.fields ?? undefined,
|
||||
};
|
||||
} catch (error: any) {
|
||||
await this.disconnect();
|
||||
throw new Error(`PostgreSQL 쿼리 실행 실패: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getTables(): Promise<TableInfo[]> {
|
||||
try {
|
||||
await this.connect();
|
||||
const result = await this.client!.query(`
|
||||
SELECT
|
||||
t.table_name,
|
||||
obj_description(quote_ident(t.table_name)::regclass::oid, 'pg_class') as table_description
|
||||
FROM information_schema.tables t
|
||||
WHERE t.table_schema = 'public'
|
||||
AND t.table_type = 'BASE TABLE'
|
||||
ORDER BY t.table_name;
|
||||
`);
|
||||
await this.disconnect();
|
||||
return result.rows.map((row) => ({
|
||||
table_name: row.table_name,
|
||||
description: row.table_description,
|
||||
columns: [], // Columns will be fetched by getColumns
|
||||
}));
|
||||
} catch (error: any) {
|
||||
await this.disconnect();
|
||||
throw new Error(`PostgreSQL 테이블 목록 조회 실패: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async getColumns(tableName: string): Promise<any[]> {
|
||||
try {
|
||||
await this.connect();
|
||||
const result = await this.client!.query(`
|
||||
SELECT
|
||||
column_name,
|
||||
data_type,
|
||||
is_nullable,
|
||||
column_default
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = $1
|
||||
ORDER BY ordinal_position;
|
||||
`, [tableName]);
|
||||
await this.disconnect();
|
||||
return result.rows;
|
||||
} catch (error: any) {
|
||||
await this.disconnect();
|
||||
throw new Error(`PostgreSQL 컬럼 정보 조회 실패: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
private formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return "0 Bytes";
|
||||
const k = 1024;
|
||||
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
|
||||
}
|
||||
}
|
||||
27
backend-node/src/interfaces/DatabaseConnector.ts
Normal file
27
backend-node/src/interfaces/DatabaseConnector.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ConnectionTestResult, TableInfo } from '../types/externalDbTypes';
|
||||
|
||||
export interface ConnectionConfig {
|
||||
host: string;
|
||||
port: number;
|
||||
database: string;
|
||||
user: string;
|
||||
password: string;
|
||||
connectionTimeoutMillis?: number;
|
||||
queryTimeoutMillis?: number;
|
||||
ssl?: boolean | { rejectUnauthorized: boolean };
|
||||
}
|
||||
|
||||
export interface QueryResult {
|
||||
rows: any[];
|
||||
rowCount?: number;
|
||||
fields?: any[];
|
||||
}
|
||||
|
||||
export interface DatabaseConnector {
|
||||
connect(): Promise<void>;
|
||||
disconnect(): Promise<void>;
|
||||
testConnection(): Promise<ConnectionTestResult>;
|
||||
executeQuery(query: string): Promise<QueryResult>;
|
||||
getTables(): Promise<TableInfo[]>;
|
||||
getColumns(tableName: string): Promise<any[]>; // 특정 테이블의 컬럼 정보 조회
|
||||
}
|
||||
59
backend-node/src/services/dbConnectionManager.ts
Normal file
59
backend-node/src/services/dbConnectionManager.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { DatabaseConnectorFactory } from '../database/DatabaseConnectorFactory';
|
||||
import { ConnectionConfig, QueryResult } from '../interfaces/DatabaseConnector';
|
||||
import { ConnectionTestResult, TableInfo } from '../types/externalDbTypes';
|
||||
|
||||
export class DbConnectionManager {
|
||||
static async testConnection(
|
||||
connectionId: number,
|
||||
dbType: string,
|
||||
config: ConnectionConfig
|
||||
): Promise<ConnectionTestResult> {
|
||||
const connector = await DatabaseConnectorFactory.createConnector(dbType, config, connectionId);
|
||||
try {
|
||||
return await connector.testConnection();
|
||||
} finally {
|
||||
await DatabaseConnectorFactory.closeConnector(connectionId, dbType); // Close after test
|
||||
}
|
||||
}
|
||||
|
||||
static async executeQuery(
|
||||
connectionId: number,
|
||||
dbType: string,
|
||||
config: ConnectionConfig,
|
||||
query: string
|
||||
): Promise<QueryResult> {
|
||||
const connector = await DatabaseConnectorFactory.createConnector(dbType, config, connectionId);
|
||||
try {
|
||||
return await connector.executeQuery(query);
|
||||
} finally {
|
||||
await DatabaseConnectorFactory.closeConnector(connectionId, dbType);
|
||||
}
|
||||
}
|
||||
|
||||
static async getTables(
|
||||
connectionId: number,
|
||||
dbType: string,
|
||||
config: ConnectionConfig
|
||||
): Promise<TableInfo[]> {
|
||||
const connector = await DatabaseConnectorFactory.createConnector(dbType, config, connectionId);
|
||||
try {
|
||||
return await connector.getTables();
|
||||
} finally {
|
||||
await DatabaseConnectorFactory.closeConnector(connectionId, dbType);
|
||||
}
|
||||
}
|
||||
|
||||
static async getColumns(
|
||||
connectionId: number,
|
||||
dbType: string,
|
||||
config: ConnectionConfig,
|
||||
tableName: string
|
||||
): Promise<any[]> {
|
||||
const connector = await DatabaseConnectorFactory.createConnector(dbType, config, connectionId);
|
||||
try {
|
||||
return await connector.getColumns(tableName);
|
||||
} finally {
|
||||
await DatabaseConnectorFactory.closeConnector(connectionId, dbType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
TableInfo,
|
||||
} from "../types/externalDbTypes";
|
||||
import { PasswordEncryption } from "../utils/passwordEncryption";
|
||||
import { DbConnectionManager } from "./dbConnectionManager";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
@@ -321,8 +322,6 @@ export class ExternalDbConnectionService {
|
||||
static async testConnectionById(
|
||||
id: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const startTime = Date.now();
|
||||
|
||||
try {
|
||||
// 저장된 연결 정보 조회
|
||||
const connection = await prisma.external_db_connections.findUnique({
|
||||
@@ -353,40 +352,20 @@ export class ExternalDbConnectionService {
|
||||
};
|
||||
}
|
||||
|
||||
// 테스트용 데이터 준비
|
||||
const testData = {
|
||||
db_type: connection.db_type,
|
||||
// 연결 설정 준비
|
||||
const config = {
|
||||
host: connection.host,
|
||||
port: connection.port,
|
||||
database_name: connection.database_name,
|
||||
username: connection.username,
|
||||
database: connection.database_name,
|
||||
user: connection.username,
|
||||
password: decryptedPassword,
|
||||
connection_timeout: connection.connection_timeout || undefined,
|
||||
ssl_enabled: connection.ssl_enabled || undefined
|
||||
connectionTimeoutMillis: connection.connection_timeout != null ? connection.connection_timeout * 1000 : undefined,
|
||||
queryTimeoutMillis: connection.query_timeout != null ? connection.query_timeout * 1000 : undefined,
|
||||
ssl: connection.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false
|
||||
};
|
||||
|
||||
// 실제 연결 테스트 수행
|
||||
switch (connection.db_type.toLowerCase()) {
|
||||
case "postgresql":
|
||||
return await this.testPostgreSQLConnection(testData, startTime);
|
||||
case "mysql":
|
||||
return await this.testMySQLConnection(testData, startTime);
|
||||
case "oracle":
|
||||
return await this.testOracleConnection(testData, startTime);
|
||||
case "mssql":
|
||||
return await this.testMSSQLConnection(testData, startTime);
|
||||
case "sqlite":
|
||||
return await this.testSQLiteConnection(testData, startTime);
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
message: `지원하지 않는 데이터베이스 타입입니다: ${testData.db_type}`,
|
||||
error: {
|
||||
code: "UNSUPPORTED_DB_TYPE",
|
||||
details: `${testData.db_type} 타입은 현재 지원하지 않습니다.`,
|
||||
},
|
||||
};
|
||||
}
|
||||
// DbConnectionManager를 통한 연결 테스트
|
||||
return await DbConnectionManager.testConnection(id, connection.db_type, config);
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
@@ -399,132 +378,6 @@ export class ExternalDbConnectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL 연결 테스트
|
||||
*/
|
||||
private static async testPostgreSQLConnection(
|
||||
testData: any,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
const { Client } = await import("pg");
|
||||
const client = new Client({
|
||||
host: testData.host,
|
||||
port: testData.port,
|
||||
database: testData.database_name,
|
||||
user: testData.username,
|
||||
password: testData.password,
|
||||
connectionTimeoutMillis: (testData.connection_timeout || 30) * 1000,
|
||||
ssl: testData.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false,
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
const result = await client.query(
|
||||
"SELECT version(), pg_database_size(current_database()) as size"
|
||||
);
|
||||
const responseTime = Date.now() - startTime;
|
||||
|
||||
await client.end();
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "PostgreSQL 연결이 성공했습니다.",
|
||||
details: {
|
||||
response_time: responseTime,
|
||||
server_version: result.rows[0]?.version || "알 수 없음",
|
||||
database_size: this.formatBytes(
|
||||
parseInt(result.rows[0]?.size || "0")
|
||||
),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
try {
|
||||
await client.end();
|
||||
} catch (endError) {
|
||||
// 연결 종료 오류는 무시
|
||||
}
|
||||
|
||||
return {
|
||||
success: false,
|
||||
message: "PostgreSQL 연결에 실패했습니다.",
|
||||
error: {
|
||||
code: "CONNECTION_FAILED",
|
||||
details: error instanceof Error ? error.message : "알 수 없는 오류",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMySQLConnection(
|
||||
testData: any,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
// MySQL 라이브러리가 없으므로 모의 구현
|
||||
return {
|
||||
success: false,
|
||||
message: "MySQL 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "MySQL 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Oracle 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testOracleConnection(
|
||||
testData: any,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "Oracle 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "Oracle 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL Server 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testMSSQLConnection(
|
||||
testData: any,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQL Server 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details: "SQL Server 라이브러리가 설치되지 않았습니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* SQLite 연결 테스트 (모의 구현)
|
||||
*/
|
||||
private static async testSQLiteConnection(
|
||||
testData: any,
|
||||
startTime: number
|
||||
): Promise<import("../types/externalDbTypes").ConnectionTestResult> {
|
||||
return {
|
||||
success: false,
|
||||
message: "SQLite 연결 테스트는 현재 지원하지 않습니다.",
|
||||
error: {
|
||||
code: "NOT_IMPLEMENTED",
|
||||
details:
|
||||
"SQLite는 파일 기반이므로 네트워크 연결 테스트가 불가능합니다.",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 바이트 크기를 읽기 쉬운 형태로 변환
|
||||
*/
|
||||
@@ -622,36 +475,26 @@ export class ExternalDbConnectionService {
|
||||
};
|
||||
}
|
||||
|
||||
// DB 타입에 따른 쿼리 실행
|
||||
switch (connection.db_type.toLowerCase()) {
|
||||
case "postgresql":
|
||||
return await this.executePostgreSQLQuery(connection, decryptedPassword, query);
|
||||
case "mysql":
|
||||
return {
|
||||
success: false,
|
||||
message: "MySQL 쿼리 실행은 현재 지원하지 않습니다."
|
||||
};
|
||||
case "oracle":
|
||||
return {
|
||||
success: false,
|
||||
message: "Oracle 쿼리 실행은 현재 지원하지 않습니다."
|
||||
};
|
||||
case "mssql":
|
||||
return {
|
||||
success: false,
|
||||
message: "SQL Server 쿼리 실행은 현재 지원하지 않습니다."
|
||||
};
|
||||
case "sqlite":
|
||||
return {
|
||||
success: false,
|
||||
message: "SQLite 쿼리 실행은 현재 지원하지 않습니다."
|
||||
};
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
message: `지원하지 않는 데이터베이스 타입입니다: ${connection.db_type}`
|
||||
};
|
||||
}
|
||||
// 연결 설정 준비
|
||||
const config = {
|
||||
host: connection.host,
|
||||
port: connection.port,
|
||||
database: connection.database_name,
|
||||
user: connection.username,
|
||||
password: decryptedPassword,
|
||||
connectionTimeoutMillis: connection.connection_timeout != null ? connection.connection_timeout * 1000 : undefined,
|
||||
queryTimeoutMillis: connection.query_timeout != null ? connection.query_timeout * 1000 : undefined,
|
||||
ssl: connection.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false
|
||||
};
|
||||
|
||||
// DbConnectionManager를 통한 쿼리 실행
|
||||
const result = await DbConnectionManager.executeQuery(id, connection.db_type, config, query);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "쿼리가 성공적으로 실행되었습니다.",
|
||||
data: result.rows
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("쿼리 실행 오류:", error);
|
||||
return {
|
||||
@@ -740,15 +583,26 @@ export class ExternalDbConnectionService {
|
||||
};
|
||||
}
|
||||
|
||||
switch (connection.db_type.toLowerCase()) {
|
||||
case "postgresql":
|
||||
return await this.getPostgreSQLTables(connection, decryptedPassword);
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
message: `지원하지 않는 데이터베이스 타입입니다: ${connection.db_type}`
|
||||
};
|
||||
}
|
||||
// 연결 설정 준비
|
||||
const config = {
|
||||
host: connection.host,
|
||||
port: connection.port,
|
||||
database: connection.database_name,
|
||||
user: connection.username,
|
||||
password: decryptedPassword,
|
||||
connectionTimeoutMillis: connection.connection_timeout != null ? connection.connection_timeout * 1000 : undefined,
|
||||
queryTimeoutMillis: connection.query_timeout != null ? connection.query_timeout * 1000 : undefined,
|
||||
ssl: connection.ssl_enabled === "Y" ? { rejectUnauthorized: false } : false
|
||||
};
|
||||
|
||||
// DbConnectionManager를 통한 테이블 목록 조회
|
||||
const tables = await DbConnectionManager.getTables(id, connection.db_type, config);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "테이블 목록을 조회했습니다.",
|
||||
data: tables
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("테이블 목록 조회 오류:", error);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user