actio_python_utils.database_functions.get_db_args¶
- actio_python_utils.database_functions.get_db_args(service=None, db_args=None, logger=None, cursor_factory=<class 'actio_python_utils.database_functions.LoggingCursor'>)[source]¶
Returns a dict of arguments to log in with psycopg2. Resolution order for connecting to a database is as follows:
service, referring to a PostgreSQL service name, normally defined in
~/.pg_service.conf
db_args, arbitrary dictionary of arguments
Environment variable
$DB_CONNECTION_STRING
with format:postgres://your_user:your_password@your_host:your_port/your_database
Environment variable
$PGSERVICE
, referring to a PostgreSQL service namecfg["db"]
, which should resolve to a dictionary of arguments
- Parameters:
service (
Optional
[str
], default:None
) – The PostgreSQL service to connect todb_args (
Optional
[Mapping
[Hashable
,Any
]], default:None
) – A mapping of database connection argumentslogger (
Optional
[Logger
], default:None
) – Optional logger to write tocursor_factory (
cursor
, default:<class 'actio_python_utils.database_functions.LoggingCursor'>
) – The class of cursor to use for the connection by default (used forservice
/$DB_CONNECTION_STRING
)
- Raises:
ValueError – If
service
anddb_args
are specified- Return type:
dict
- Returns:
The dict of login arguments