(req: NextApiRequest, res: NextApiResponse)
| 7 | // POST /api/connection/execute |
| 8 | // req body: { connection: Connection, db: string, statement: string } |
| 9 | const 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 | |
| 35 | export default handler; |
nothing calls this directly
no test coverage detected