import { Connection, Engine, ExecutionResult } from "@/types"; import mysql from "./mysql"; import postgres from "./postgres"; import mssql from "./mssql"; export interface Connector { testConnection: () => Promise; execute: ( databaseName: string, statement: string ) => Promise; getDatabases: () => Promise; getTables: (databaseName: string) => Promise; getTableStructure: ( databaseName: string, tableName: string, structureFetched: (tableName: string, structure: string) => void ) => Promise; getTableStructureBatch: ( databaseName: string, tableNameList: string[], structureFetched: (tableName: string, structure: string) => void ) => Promise; } export const newConnector = (connection: Connection): Connector => { switch (connection.engineType) { case Engine.MySQL: return mysql(connection); case Engine.PostgreSQL: return postgres(connection); case Engine.MSSQL: return mssql(connection); default: throw new Error("Unsupported engine type."); } };