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
|
### Postman
|
||||||
|
|
||||||
|
|
||||||
Zum Debuggen der Flask App verwende ich dieses Tutorial:
|
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
|
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 mysql.connector
|
||||||
import pydapper
|
import pydapper
|
||||||
import logging
|
import logging
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
connection_pool = None
|
connection_pool = None
|
||||||
|
|
||||||
def initPool():
|
def initPool():
|
||||||
try:
|
try:
|
||||||
global connection_pool
|
global connection_pool
|
||||||
connection_pool = mysql.connector.connect(
|
|
||||||
host="lager", # TODO: move these settings outside the code!
|
config_path = './src/server/BreCal/connection_data.json'
|
||||||
port=3306,
|
print (os.getcwd())
|
||||||
user="ds",
|
if not os.path.exists(config_path):
|
||||||
password="HalloWach23",
|
print ('cannot find ' + config_path)
|
||||||
pool_name="brecal_pool",
|
exit(1)
|
||||||
pool_size=20,
|
|
||||||
database="bremen_calling"
|
f = open(config_path);
|
||||||
)
|
connection_data = json.load(f)
|
||||||
|
|
||||||
|
connection_pool = mysql.connector.connect(**connection_data)
|
||||||
|
|
||||||
commands = pydapper.using(connection_pool)
|
commands = pydapper.using(connection_pool)
|
||||||
data = commands.query_single("SELECT id from `user`")
|
data = commands.query_single("SELECT id from `user`")
|
||||||
@ -23,4 +27,6 @@ def initPool():
|
|||||||
|
|
||||||
except mysql.connector.PoolError as e:
|
except mysql.connector.PoolError as e:
|
||||||
logging.error(f"Failed to create connection pool: {e}")
|
logging.error(f"Failed to create connection pool: {e}")
|
||||||
|
print(e)
|
||||||
|
except e:
|
||||||
print(e)
|
print(e)
|
||||||
Loading…
Reference in New Issue
Block a user