mysql createPool
This commit is contained in:
@@ -1,19 +1,9 @@
|
||||
// pages/api/talas_v5_DB/pois/deletePoi.js
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
// Erstellen eines Pools von Datenbankverbindungen
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: process.env.DB_PORT,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0,
|
||||
});
|
||||
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const pool = getPool(); // Singleton-Pool verwenden
|
||||
|
||||
if (req.method !== "DELETE") {
|
||||
return res.status(405).json({ error: "Nur DELETE Methode erlaubt" });
|
||||
}
|
||||
@@ -26,9 +16,13 @@ export default async function handler(req, res) {
|
||||
|
||||
const query = "DELETE FROM poi WHERE idPoi = ?";
|
||||
|
||||
let connection;
|
||||
|
||||
try {
|
||||
connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
|
||||
|
||||
// Ausführen der Abfrage mit dem Verbindungspool
|
||||
const [results] = await pool.query(query, [id]);
|
||||
const [results] = await connection.query(query, [id]);
|
||||
|
||||
if (results.affectedRows > 0) {
|
||||
res.status(200).json({ message: "POI erfolgreich gelöscht" });
|
||||
@@ -36,7 +30,9 @@ export default async function handler(req, res) {
|
||||
res.status(404).json({ error: "POI nicht gefunden" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Löschen des POI 3:", error);
|
||||
console.error("Fehler beim Löschen des POI:", error);
|
||||
res.status(500).json({ error: "Fehler beim Löschen des POI" });
|
||||
} finally {
|
||||
if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user