Files
CorrectRoadH 40e86fbdaf fix: too many connect error (#71)
* add fetch all struct

* add other database implement

* rename method name

* adjust the order of functions

* eslint

* eslint

* eslint

* eslint

* eslint

* fix error end when fetch schema batch
2023-05-04 23:36:48 +08:00

38 lines
1.1 KiB
TypeScript

import { Connection, Engine, ExecutionResult } from "@/types";
import mysql from "./mysql";
import postgres from "./postgres";
import mssql from "./mssql";
export interface Connector {
testConnection: () => Promise<boolean>;
execute: (
databaseName: string,
statement: string
) => Promise<ExecutionResult>;
getDatabases: () => Promise<string[]>;
getTables: (databaseName: string) => Promise<string[]>;
getTableStructure: (
databaseName: string,
tableName: string,
structureFetched: (tableName: string, structure: string) => void
) => Promise<void>;
getTableStructureBatch: (
databaseName: string,
tableNameList: string[],
structureFetched: (tableName: string, structure: string) => void
) => Promise<void>;
}
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.");
}
};