Django Backend-neutral DictCursor

帅比萌擦擦* 提交于 2019-12-05 10:44:16

You could write it in a couple of lines :)

def dict_cursor(cursor):
    description = [x[0] for x in cursor.description]
    for row in cursor:
        yield dict(zip(description, row))

Or if you really want to save space:

simplify_description = lambda cursor: [x[0] for x in cursor.description]
dict_cursor = lambda c, d: dict(zip(d, r) for r in c))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!