diff --git a/pgloader/db.py b/pgloader/db.py index 7fb737e..f036d6a 100644 --- a/pgloader/db.py +++ b/pgloader/db.py @@ -51,16 +51,13 @@ elif PSYCOPG_VERSION == 2: class db: """ a db connexion and utility class """ def __init__(self, - host, port, base, user, passwd, + dsn, client_encoding = PG_CLIENT_ENCODING, copy_every = 10000, commit_every = 1000, connect = True): """ Connects to the specified database """ self.log = log self.dbconn = None - self.dsn = "host=%s port=%d user=%s dbname=%s password=%s" \ - % (host, port, user, base, passwd) - self.connect = "-h %s -p %s -U %s" % (host, port, user) - self.base = base + self.dsn = dsn # those parameters can be overwritten after db init # here's their default values diff --git a/pgloader/pgloader.py b/pgloader/pgloader.py index 5b1becd..afbdfa2 100644 --- a/pgloader/pgloader.py +++ b/pgloader/pgloader.py @@ -157,12 +157,21 @@ class PGLoader(threading.Thread): return try: - self.db = db(config.get(section, 'host'), - config.getint(section, 'port'), - config.get(section, 'base'), - config.get(section, 'user'), - config.get(section, 'pass'), - connect = False) + dsn = []; + if config.has_option(section, 'host'): + dsn.append ("host=%s" % config.get(section, 'host')) + if config.has_option(section, 'port'): + dsn.append ("port=%d" % config.getint(section, 'port')) + if config.has_option(section, 'base'): + dsn.append ("dbname=%s" % config.get(section, 'base')) + if config.has_option(section, 'user'): + dsn.append ("user=%s" % config.get(section, 'user')) + if config.has_option(section, 'pass'): + dsn.append ("password=%s" % config.get(section, 'pass')) + if config.has_option(section, 'sslmode'): + dsn.append ("sslmode=%s" % config.get(section, 'sslmode')) + + self.db = db(" ".join (dsn), connect = False) for opt in ['client_encoding', 'datestyle', 'lc_messages']: if config.has_option(section, opt):