POI hinzufügen mit mysql2 Bibliothek irgendwie nicht optimal, mysql Bibliothek funktioniert gut, Pool auch genutzt in mysql Bibliothek für mehr Performence und weniger Probleme mit conntctions
This commit is contained in:
@@ -1,45 +1,35 @@
|
||||
// pages/api/talas_v5_DB/pois/addLocation.js
|
||||
import mysql from "mysql2/promise";
|
||||
// pages/api/addLocation.js
|
||||
import mysql from "mysql";
|
||||
|
||||
// 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,
|
||||
connectionLimit: 10, // Maximale Anzahl gleichzeitiger Verbindungen
|
||||
});
|
||||
|
||||
export default async function handler(req, res) {
|
||||
export default function handler(req, res) {
|
||||
if (req.method === "POST") {
|
||||
const { name, poiTypeId, latitude, longitude, idLD } = req.body;
|
||||
console.log("Received data:", req.body); // Überprüfen der empfangenen Daten
|
||||
|
||||
if (!name || !poiTypeId || !latitude || !longitude || !idLD) {
|
||||
return res.status(400).json({ error: "Alle Felder sind erforderlich" });
|
||||
}
|
||||
|
||||
const query = `
|
||||
INSERT INTO poi (description, idPoiTyp, position, idLD)
|
||||
VALUES (?, ?, ST_GeomFromText(?), ?)
|
||||
`;
|
||||
const query = "INSERT INTO poi (description, idPoiTyp, position, idLD) VALUES (?, ?, ST_GeomFromText(?),?)";
|
||||
const point = `POINT(${longitude} ${latitude})`;
|
||||
const values = [name, poiTypeId, point, idLD];
|
||||
|
||||
try {
|
||||
// Ausführen der Abfrage mit dem Verbindungspool
|
||||
const [results] = await pool.query(query, values);
|
||||
// Verwende den Pool, um eine Verbindung zu bekommen und die Query auszuführen
|
||||
pool.query(query, values, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Einfügen des Standorts:", error);
|
||||
return res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||
}
|
||||
res.status(200).json({
|
||||
id: results.insertId,
|
||||
message: "Standort erfolgreich hinzugefügt",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Einfügen des Standorts:", error);
|
||||
res.status(500).json({ error: "Ein Fehler ist aufgetreten" });
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.setHeader("Allow", ["POST"]);
|
||||
res.status(405).end(`Method ${req.method} Not Allowed`);
|
||||
|
||||
Reference in New Issue
Block a user