Skip to content

Commit

Permalink
Add get_tfdb_addr() to sql.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Dec 20, 2020
1 parent 9f10906 commit 7215f14
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pyhelpers/sql.py
Expand Up @@ -7,6 +7,7 @@
import csv
import gc
import getpass
import inspect
import io
import tempfile

Expand All @@ -16,6 +17,35 @@
from .ops import confirmed


def get_tfdb_addr(db_cls):
"""
Get default address of the Track Fixity database.
:param db_cls: a class representation of a database
:type db_cls: object
:return: default address of database
:rtype: str
**Test**::
>>> from pyhelpers.sql import get_tfdb_addr, PostgreSQL
>>> tfdb_addr = get_tfdb_addr(db_cls=PostgreSQL)
>>> print(tfdb_addr)
None:***@None:None/None
"""

args_spec = inspect.getfullargspec(db_cls)

args_dict = dict(zip([x for x in args_spec.args if x != 'self'], args_spec.defaults))

db_address = "{}:***@{}:{}/{}".format(args_dict['username'], args_dict['host'],
args_dict['port'], args_dict['database_name'])

return db_address


class PostgreSQL:
"""
A class for a basic `PostgreSQL <https://www.postgresql.org/>`_ instance.
Expand Down

0 comments on commit 7215f14

Please sign in to comment.