mysql createPool

This commit is contained in:
ISA
2024-09-02 09:06:49 +02:00
parent ac80c8c619
commit ea46bd771b
52 changed files with 2026 additions and 437 deletions

View File

@@ -1,19 +1,9 @@
// pages/api/talas_v5_DB/pois/updatePoi.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(); // Verwende den Singleton-Pool
if (req.method !== "POST") {
return res.status(405).json({ error: "Nur POST Methode erlaubt" });
}
@@ -30,8 +20,12 @@ export default async function handler(req, res) {
WHERE idPoi = ?
`;
let connection;
try {
const [results] = await pool.query(query, [description, idPoiTyp, idLD, idPoi]);
connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
const [results] = await connection.query(query, [description, idPoiTyp, idLD, idPoi]);
if (results.affectedRows > 0) {
res.status(200).json({ message: "POI erfolgreich aktualisiert" });
@@ -41,5 +35,7 @@ export default async function handler(req, res) {
} catch (error) {
console.error("Fehler beim Aktualisieren des POI:", error);
res.status(500).json({ error: "Fehler beim Aktualisieren des POI" });
} finally {
if (connection) connection.release(); // Gib die Verbindung zurück in den Pool
}
}