MCPcopy Create free account
hub / github.com/sqlchat/sqlchat / handler

Function handler

src/pages/api/connection/db_schema.ts:10–35  ·  view source on GitHub ↗
(req: NextApiRequest, res: NextApiResponse)

Source from the content-addressed store, hash-verified

8// req body: { connection: Connection, db: string }
9// It's mainly used to get the database list.
10const handler = async (req: NextApiRequest, res: NextApiResponse) => {
11 if (req.method !== "POST") {
12 return res.status(405).json([]);
13 }
14
15 let connection = req.body.connection as Connection;
16 if (connection.engineType === Engine.TiDB) {
17 connection = changeTiDBConnectionToMySQL(connection);
18 }
19
20 const db = req.body.db as string;
21
22 try {
23 const connector = newConnector(connection);
24 const schemaList: Schema[] = await connector.getTableSchema(db);
25
26 res.status(200).json({
27 data: schemaList,
28 });
29 } catch (error: any) {
30 res.status(400).json({
31 message: error.message || "Failed to get database schema.",
32 code: error.code || "UNKNOWN",
33 });
34 }
35};
36
37export default handler;

Callers

nothing calls this directly

Calls 2

newConnectorFunction · 0.90

Tested by

no test coverage detected