Project: mblog Author: moling3650 File: orm.py (MIT License) View Source Project

def select(sql, args, size=None):
    log(sql, args)
    # ??????????????????with???????????conn?????????
    async with __pool.get() as conn:
        # ????????DictCursor????dict?????????????????????SQL
        async with conn.cursor(aiomysql.DictCursor) as cur:
            await cur.execute(sql.replace('?', '%s'), args)  # ?sql??'?'???'%s'???mysql????????%s
            # ????size
            if size:
                resultset = await cur.fetchmany(size)  # ???????????
            else:
                resultset = await cur.fetchall()      # ????????
        logging.info('rows returned: %s' % len(resultset))
        return resultset

# ??SQL?INSERT INTO?UPDATE?DELETE???execute???????????????
  • python

    Python (发音:[ paiθ(ə)n; (US) paiθɔn ]n. 蟒蛇,巨蛇 ),是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的通用型语言,已经具有十多年的发…

    7952 引用 • 22 回帖 • 2 关注
  • SQL
    260 引用
感谢    赞同    分享    收藏    关注    反对    举报    ...