def connect_to_database(user: str=None, host: str=None, password: str=None):
"""Retrieve a connection to the database server.
:param user: Database username
:param host: Database host url
:param password: Database password
:return: A psycopg2 `connection`
"""
if not host:
host = os.getenv('POSTGRES_HOST', 'localhost')
if not user:
user = os.getenv('POSTGRES_USER', 'postgres')
if not password:
password = os.getenv('POSTGRES_PASSWORD', 'p0stgres')
return connect(user=user, password=password, host=host, cursor_factory=DictCursor)
评论列表
文章目录