(req: NextApiRequest, res: NextApiResponse)
| 8 | // req body: { connection: Connection, db: string } |
| 9 | // It's mainly used to get the database list. |
| 10 | const 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 | |
| 37 | export default handler; |
nothing calls this directly
no test coverage detected