在 peewee 中获取 SQL 查询计数

Get SQL query count in peewee

是否可以在 peewee 中计算查询数? 在Django中制作如下:

from django.db import connection
print len(connection.queries)

您可以像 here 那样操作:子类 Database 将其设置为对查询进行计数:

def execute(*args, **kwargs):
    self.counter += 1  # or put the query into some list, as you like
    return super().execute(args, kwargs)