mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-28 02:24:49 +08:00
refactor: move codes into src folder
This commit is contained in:
22
src/lib/connectors/index.ts
Normal file
22
src/lib/connectors/index.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Connection, Engine } from "@/types";
|
||||
import mysql from "./mysql";
|
||||
import postgres from "./postgres";
|
||||
|
||||
export interface Connector {
|
||||
testConnection: () => Promise<boolean>;
|
||||
execute: (databaseName: string, statement: string) => Promise<any>;
|
||||
getDatabases: () => Promise<string[]>;
|
||||
getTables: (databaseName: string) => Promise<string[]>;
|
||||
getTableStructure: (databaseName: string, tableName: string) => Promise<string>;
|
||||
}
|
||||
|
||||
export const newConnector = (connection: Connection): Connector => {
|
||||
switch (connection.engineType) {
|
||||
case Engine.MySQL:
|
||||
return mysql(connection);
|
||||
case Engine.PostgreSQL:
|
||||
return postgres(connection);
|
||||
default:
|
||||
throw new Error("Unsupported engine type.");
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user