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
评论列表
文章目录