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

Function handler

src/pages/api/connection/execute.ts:9–33  ·  view source on GitHub ↗
(req: NextApiRequest, res: NextApiResponse)

Source from the content-addressed store, hash-verified

7// POST /api/connection/execute
8// req body: { connection: Connection, db: string, statement: string }
9const handler = async (req: NextApiRequest, res: NextApiResponse) => {
10 if (req.method !== "POST") {
11 return res.status(405).json(false);
12 }
13
14 let connection = req.body.connection as Connection;
15 if (connection.engineType === Engine.TiDB) {
16 connection = changeTiDBConnectionToMySQL(connection);
17 }
18 const db = req.body.db as string;
19 const statement = req.body.statement as string;
20
21 try {
22 const connector = newConnector(connection);
23 const result = await connector.execute(db, statement);
24 res.status(200).json({
25 data: result,
26 });
27 } catch (error: any) {
28 res.status(400).json({
29 message: error.message || "Failed to execute statement.",
30 code: error.code || "UNKNOWN",
31 });
32 }
33};
34
35export default handler;

Callers

nothing calls this directly

Calls 2

newConnectorFunction · 0.90

Tested by

no test coverage detected