database.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:anxiety 作者: hectron 项目源码 文件源码
def get_database_connection(db_name: str=None, user: str=None, host: str=None, password: str=None):
    """Retrieve the database connection.

    This returns a database connection to the database, not just the database
    server.

    :param db_name:     Name of the database to connect to
    :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 db_name:
        db_name = os.getenv('POSTGRES_DB', 'anxiety')
    if not user:
        user = os.getenv('POSTGRES_USER', 'postgres')
    if not password:
        password = os.getenv('POSTGRES_PASSWORD', 'p0stgres')

    return connect(database=db_name, user=user, password=password, host=host, cursor_factory=DictCursor)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号