Spaces:
Sleeping
Sleeping
File size: 820 Bytes
645ad9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import { NextApiRequest, NextApiResponse } from "next";
import { createConnection, getTables } from "@/utils/database";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (req.method !== "POST") {
return res.status(405).json({ message: "Method not allowed" });
}
const { dbUri } = req.body;
if (!dbUri) {
return res.status(400).json({
message: "Database URI is required"
});
}
let connection;
try {
connection = await createConnection(dbUri);
const tables = await getTables(connection);
await connection.end();
return res.status(200).json({ tables });
} catch (error: any) {
await connection?.end();
return res.status(500).json({
message: "Failed to fetch tables",
details: error.message
});
}
} |