database in service

This commit is contained in:
2021-01-15 12:53:46 +01:00
parent ceadf3338f
commit 24482da680
4 changed files with 97 additions and 21 deletions

View File

@ -1,24 +1,24 @@
HEROES = [
{ "id": 1, "name": "Wolfgang" },
{ "id": 2, "name": "Andreas" },
{ "id": 3, "name": "Frank" },
{ "id": 4, "name": "Thomas" },
{ "id": 5, "name": "Barbara" },
{ "id": 6, "name": "Robert" },
{ "id": 7, "name": "Raphael" },
{ "id": 8, "name": "Lucia" },
{ "id": 9, "name": "Gregor" },
]
from dbpool import getConnection
from heroes_mock import HEROES
def get_heroes():
if HEROES:
return HEROES
else:
return 'No heroes available', 404
# if HEROES:
# return HEROES
# else:
# return 'No heroes available', 404
try:
dbh = getConnection()
heroes = []
cur = dbh.cursor()
cur.execute("SELECT id, name FROM hero")
for (id, name) in cur:
heroes.append({"id": id, "name": name})
return heroes
except Exception:
return 500, str(Exception)
finally:
dbh.close()
def get_hero(id=None):
try: