db.py 文件源码

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

项目:arthur-redshift-etl 作者: harrystech 项目源码 文件源码
def extract_dsn(dsn_dict: Dict[str, str], read_only=False):
    """
    Break the connection string into a JDBC URL and connection properties.

    This is necessary since a JDBC URL may not contain all the properties needed
    to successfully connect, e.g. username, password.  These properties must
    be passed in separately.

    Use the postgresql subprotocol and driver regardless of whether the connection
    string's protocol was postgres or redshift.
    """
    dsn_properties = dict(dsn_dict)  # so as to not mutate the argument
    dsn_properties.update({
        "ApplicationName": __name__,
        "readOnly": "true" if read_only else "false",
        "driver": "org.postgresql.Driver"
    })
    if "port" in dsn_properties:
        jdbc_url = "jdbc:postgresql://{host}:{port}/{database}".format(**dsn_properties)
    else:
        jdbc_url = "jdbc:postgresql://{host}/{database}".format(**dsn_properties)
    return jdbc_url, dsn_properties
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号