mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-27 10:06:23 +08:00

* 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
38 lines
1.1 KiB
TypeScript
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.");
|
|
}
|
|
};
|