Skip to content

Commit

Permalink
Update server
Browse files Browse the repository at this point in the history
  • Loading branch information
slimovich committed Jul 1, 2020
1 parent 1f04f9b commit e875d7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_app() -> FastAPI:
async def _startup() -> None:
LOGGER.info("Check existing database")
database: bool = await existing_database(db, DB_NAME)

if not database:
LOGGER.error(f"please create the required database before running the server db_name = {DB_NAME}")
else:
Expand Down
13 changes: 8 additions & 5 deletions src/utils/sql.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from typing import List

from gino.ext.starlette import Gino

async def existing_database(db, name) -> bool:

async def existing_database(db: Gino, name: str) -> bool:
""" Return the names of existing database """
query = """

query: str = """
SELECT datname
FROM pg_database;
"""
raws = await db.all(db.text(query))
raws: List = await db.all(db.text(query))
for raw in raws:
if raw[0] == name:
return True
return False
return False

0 comments on commit e875d7a

Please sign in to comment.