def __init__(self, dbname, username, password, host, port, cursor_type=None, verbose=False):
self.sshtunnel = None
self._psql_conn = None
self.verbose = verbose
# self.connection_string = (
# "dbname={} user={} "
# "password={} " if password is not None else "{}"
# "host={} " if host is not None else "{}"
# "port={} " if host is not None else "{}").format(
# dbname,
# username,
# password if password is not None else "",
# host if host is not None else "",
# port if port is not None else "")
self.dbname = dbname
self.username = username
self.password = password
self.host = host
self.port = int(port) if port != "" else 5432
# self.connection_string = "dbname={} ".format(dbname)
# self.connection_string += "user={} ".format(username)
# self.connection_string += "password={} ".format(password) if password is not None else ""
# self.connection_string += "host={} ".format(host) if host is not None else ""
# self.connection_string += "port={}".format(port) if host is not None else ""
#
# print self.connection_string
if cursor_type is None:
self.cursor_factory = NamedTupleCursor
elif cursor_type == "standard":
self.cursor_factory = None
elif cursor_type == "namedtuple":
self.cursor_factory = NamedTupleCursor
elif cursor_type == "dictlike":
self.cursor_factory = DictCursor
elif cursor_type == "dict":
self.cursor_factory = RealDictCursor
else:
raise Exception("'cursor_type' unknonw: '{}'".format(cursor_type))
# self.conn = pgres.connect(connection_string, cursor_factory=NamedTupleCursor)
# self._conn = pgres.connect(connection_string)
self.connect(self.cursor_factory)
评论列表
文章目录