tornado + tormysql 异步使用数据库 提高并发能力

基础

https://blog.csdn.net/yangxiaodong88/article/details/86494125
本篇文章已经讲解了怎么基础使用tormysql 异步客户端去操作mysql

封装前的demo

主要是在 db_base 里面对增删
demo 获取集合的sql

     @classmethod
    async def get_10(cls):
        async with await pool.Connection() as conn:
            async with conn.cursor() as cursor:
                data = dict()
                data["state"] = 1
                data["approval_state"] = 3
                data["parent_id"] = "NULL"
                dd = ["4eb1c040f14111e8870c509a4c9436be", "d5fe1550f13a11e8ab55509a4c9436be"]
                data["situation_id"] = tuple(dd)
                # sql = "SELECT id,created_at,content FROM comment where  state={state} and approval_state !='{approval_state}' and parent_id IS NULL and situation_id in {situation_id}"
                sql = "SELECT id,created_at,content FROM comment where  state={state} and approval_state !='{approval_state}' and parent_id IS {parent_id} and situation_id in {situation_id}"
                # sql = "SELECT id,created_at,content FROM comment WHERE parent_id is NULL "
                sql = sql.format(**data)
               
                await cursor.execute(sql)
                data = cursor.fetchall()
                
        return data

    @classmethod
    async def get(cls):
        async with await pool.Connection() as conn:
            async with conn.cursor() as cursor:
                # data = dict()
                # data["db_name"] = "configuration"
                # data["timestamp"] = "timestamp"
                # data["identity"] = "identity"
                # sql = "SELECT {timestamp},{identity} FROM {db_name} "
                # sql = sql.format(**data)
                # await cursor.execute(sql)
                # data = cursor.fetchone()

                data = dict()
                data["db_name"] = "configuration"
                data["aa"] = "timestamp" + "," + "identity"
                # field_list = ["timestamp", "identity"] # ok
                # field_list = ["*"] # ok
                field_list = ["timestamp as tt", "identity"]  # ok
                field_list = ["sum(threshold) as thr"]  # ok 可以有哈哈
                field_list = ["identity", "threshold"]  # ok 可以有哈哈
                data["field"] = ",".join(field_list)
                # condition = "threshold >100"  # 可行
                condition = "threshold >100 order by threshold desc"  # 可行 perfect
                condition = "id in(1,3,4)"  # ok
                condition = "description in('信誉积分下限')"  # 真棒
                # ======
                # ids = [1, 3, 5]
                # ids = tuple(ids)
                # condition = "id in {ids}".format(ids=ids)  # 真棒
                ###======= 可行
                # a = 1, 2, 3  # 这种可以
                a = [1, 3, 5]

                # ids = [1]
                # ids = ",".join(ids)
                # ids = tuple(ids)
                # ids = (1)  # 这个不可以
                # condition = "id in {ids}".format(ids=ids)  # 真棒
                # condition = "id in (1)"  # 真棒 这个可以
                # condition = "id in {ids}".format(ids=ids)  # 真棒 这个可以
                # condition = "id in {ids}".format(ids=a)  # 真棒 这个可以
                def get_in_data(data_):
                    if isinstance(data_
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值