Compare commits
4 Commits
2ecf7ae56d
...
0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 06e24e35e1 | |||
| 523ac2228d | |||
| 95a232fb78 | |||
| 355aff8cf3 |
@ -17,6 +17,7 @@ def set_connection():
|
|||||||
logger.info('Connection to PostreSQL DB set successfully')
|
logger.info('Connection to PostreSQL DB set successfully')
|
||||||
except psycopg2.Error as e:
|
except psycopg2.Error as e:
|
||||||
logger.error(f'Failed to set connection to the PostgreSQL DB: {e.pgerror}')
|
logger.error(f'Failed to set connection to the PostgreSQL DB: {e.pgerror}')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def close_connection(connection):
|
def close_connection(connection):
|
||||||
|
|||||||
@ -12,12 +12,15 @@ if config.enable_api_docs:
|
|||||||
else:
|
else:
|
||||||
docs_url = None
|
docs_url = None
|
||||||
|
|
||||||
|
schema_name = 'harticle'
|
||||||
|
table_name = 'articles'
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
DBwork.set_connection()
|
DBwork.set_connection()
|
||||||
DBwork.schema_creator(config.schema_name, db.connection)
|
DBwork.schema_creator(schema_name, db.connection)
|
||||||
DBwork.table_creator(config.schema_name, config.table_name, db.connection)
|
DBwork.table_creator(schema_name, table_name, db.connection)
|
||||||
yield
|
yield
|
||||||
DBwork.close_connection(db.connection)
|
DBwork.close_connection(db.connection)
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,6 @@ postgres_user = config('POSTGRES_USER')
|
|||||||
postgres_password = config('POSTGRES_PASSWORD')
|
postgres_password = config('POSTGRES_PASSWORD')
|
||||||
host_name = config('HOST_NAME')
|
host_name = config('HOST_NAME')
|
||||||
port = config('PG_PORT')
|
port = config('PG_PORT')
|
||||||
schema_name = config('SCHEMA_NAME')
|
|
||||||
table_name = config('TABLE_NAME')
|
|
||||||
|
|
||||||
enable_api_docs = config('ENABLE_API_DOCS', cast=bool)
|
enable_api_docs = config('ENABLE_API_DOCS', cast=bool)
|
||||||
|
|
||||||
|
|||||||
@ -5,4 +5,4 @@ from app_creator import create_app
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = create_app()
|
app = create_app()
|
||||||
uvicorn.run(app=app, host="127.0.0.1", port=8000, log_level=uvicorn_logging_level.lower())
|
uvicorn.run(app=app, host="0.0.0.0", port=8000, log_level=uvicorn_logging_level.lower())
|
||||||
|
|||||||
Reference in New Issue
Block a user