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

@@ -2,28 +2,18 @@
// in tals5 http://10.10.0.13/talas5/Management/PriorityConfig.aspx beinhaltet die Tabelle prio die Prioritäten der Meldungen (Level 1-4) oder (0-4) je nachdem DB-Design
// das ist die API, die die Prioritäten zurückgibt
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
try {
// Ausführen der Datenbankabfrage
const query = "SELECT idprio, level, name, color FROM prio";
const results = await pool.query(query);
const [results] = await pool.query(query);
// Wichtig: Senden Sie die Antwort zurück
res.status(200).json(results[0]); // Da mysql2 Tuple [rows, fields] zurückgibt, wählen wir nur rows mit [0]
res.status(200).json(results); // Nur rows werden zurückgegeben
} catch (error) {
console.error("Fehler beim Abrufen der API", error);
res.status(500).json({ error: "Fehler bei der Abfrage" });