db.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Scalable-PaQL-Queries 作者: mattfeel 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号