db_op.py 文件源码

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

项目:2016-NCTU_find_roommate-API-server 作者: Microsheep 项目源码 文件源码
def get(self, query, params, dry_output=False):
        """
        Use this method to fetch data from db.
            param query: (str) actual query to be executed
            param dry_output: (bool) switch output style
            return: If dry_output True - output tuple of tuples, otherwise list of dicts
        """
        #print(datetime.now())
        #print("DB_GET: "+query)
        #print("INPUT: "+str(params))
        with (yield self.pool.Connection()) as conn:
            with conn.cursor() as cursor:
                yield cursor.execute(query, params)
                yield conn.commit()
                data = rows = cursor.fetchall()
                cols = [x[0] for x in cursor.description]
        if not dry_output:
            data = []
            for row in rows:
                record = {}
                for prop, val in zip(cols, row):
                    record[prop] = val
                data.append(record)
        raise gen.Return(data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号