34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
// pages/api/talas_v5_DB/poiTyp/readPoiTyp.js
|
|
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
|
|
|
export default async function handler(req, res) {
|
|
const pool = getPool(); // Verwende den Singleton-Pool
|
|
|
|
if (req.method !== "GET") {
|
|
res.setHeader("Allow", ["GET"]);
|
|
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
|
}
|
|
|
|
const query = "SELECT * FROM poityp";
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
|
|
|
|
// Führe die Abfrage aus
|
|
const [results] = await connection.query(query);
|
|
|
|
if (results.length === 0) {
|
|
return res.status(200).json({ warning: "Keine Einträge gefunden in readPoiTyp.js" });
|
|
}
|
|
|
|
res.status(200).json(results);
|
|
} catch (error) {
|
|
console.error("Fehler beim Abfragen der Datenbank:", error);
|
|
res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
|
} finally {
|
|
if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
|
|
}
|
|
}
|