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)
db_op.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录