Datenmodell neu, Verbindungsdaten Flask aus einer Datei laden

This commit is contained in:
Daniel Schick 2023-06-16 12:25:53 +02:00
parent 31b52038b2
commit fdeacdca6e
5 changed files with 25 additions and 12 deletions

View File

@ -19,7 +19,5 @@ Ein erster Gedanke des Datenbank-Layouts sieht folgendermaßen aus:
### Postman
Zum Debuggen der Flask App verwende ich dieses Tutorial:
https://code.visualstudio.com/docs/python/tutorial-flask#_create-a-project-environment-for-the-flask-tutorial

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"host" : "lager",
"port" : 3306,
"user" : "ds",
"password" : "HalloWach23",
"pool_name" : "brecal_pool",
"pool_size" : 20,
"database" : "bremen_calling"
}

View File

@ -1,21 +1,25 @@
import mysql.connector
import pydapper
import logging
import json
import os
connection_pool = None
def initPool():
try:
global connection_pool
connection_pool = mysql.connector.connect(
host="lager", # TODO: move these settings outside the code!
port=3306,
user="ds",
password="HalloWach23",
pool_name="brecal_pool",
pool_size=20,
database="bremen_calling"
)
config_path = './src/server/BreCal/connection_data.json'
print (os.getcwd())
if not os.path.exists(config_path):
print ('cannot find ' + config_path)
exit(1)
f = open(config_path);
connection_data = json.load(f)
connection_pool = mysql.connector.connect(**connection_data)
commands = pydapper.using(connection_pool)
data = commands.query_single("SELECT id from `user`")
@ -24,3 +28,5 @@ def initPool():
except mysql.connector.PoolError as e:
logging.error(f"Failed to create connection pool: {e}")
print(e)
except e:
print(e)