Datenmodell neu, Verbindungsdaten Flask aus einer Datei laden
This commit is contained in:
parent
31b52038b2
commit
fdeacdca6e
@ -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.
9
src/server/BreCal/connection_data.json
Normal file
9
src/server/BreCal/connection_data.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"host" : "lager",
|
||||
"port" : 3306,
|
||||
"user" : "ds",
|
||||
"password" : "HalloWach23",
|
||||
"pool_name" : "brecal_pool",
|
||||
"pool_size" : 20,
|
||||
"database" : "bremen_calling"
|
||||
}
|
||||
@ -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)
|
||||
Reference in New Issue
Block a user