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:
ISA
2024-08-14 20:38:55 +02:00
parent e0c23402f7
commit ad7c7f84a0
2 changed files with 32 additions and 42 deletions

View File

@@ -17,30 +17,30 @@
#########################
DB_HOST=10.10.0.70
DB_USER=root
DB_PASSWORD="root#$"
DB_NAME=talas_v5
DB_PORT=3306
#########################
NEXT_PUBLIC_BASE_URL="http://10.10.0.70/talas5/devices/"
NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.70"
#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.13:3000/mapTiles/{z}/{x}/{y}.png"
NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
#########################
#DB_HOST=192.168.10.167
#DB_HOST=10.10.0.70
#DB_USER=root
#DB_PASSWORD="root#$"
#DB_NAME=talas_v5
#DB_PORT=3306
#########################
#NEXT_PUBLIC_BASE_URL="http://10.10.0.70/talas5/devices/"
#NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
#NEXT_PUBLIC_PROXY_TARGET="http://10.10.0.70"
#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.13:3000/mapTiles/{z}/{x}/{y}.png"
NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
#########################
DB_HOST=192.168.10.167
DB_USER=root
DB_PASSWORD="root#$"
DB_NAME=talas_v5
DB_PORT=3306
#########################
#URLs für den Client (clientseitig)
#NEXT_PUBLIC_BASE_URL="http://192.168.10.167/talas5/devices/"
#NEXT_PUBLIC_SERVER_URL="http://192.168.10.167"
#NEXT_PUBLIC_PROXY_TARGET="http://192.168.10.167"
NEXT_PUBLIC_BASE_URL="http://192.168.10.167/talas5/devices/"
NEXT_PUBLIC_SERVER_URL="http://192.168.10.167"
NEXT_PUBLIC_PROXY_TARGET="http://192.168.10.167"
#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://192.168.10.14:3000/mapTiles/{z}/{x}/{y}.png"

View File

@@ -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`);