Python 3.x Tortoise-orm 删除数据库SQLite中的所有值

Python 3.x Tortoise-orm Delete all values inside the database SQLite

所以我最近开始学习 tortoise-orm。但是我有一个问题:如何获取SQLite数据库中的所有数据并删除所有数据?

前型号:

from tortoise.models import Model
from tortoise import fields

class Counter(Model):
    count = fields.IntField()

    def __str__(self):
        return self.name

你可以:

  • 通过查询Counter.all()获取所有数据。等待这将为您提供 python 个 Counter 个对象的列表。
  • 删除整个数据库,await Tortoise._drop_database()

小心删除数据库,您将丢失所有数据

Tries to drop all databases provided in config passed to .init() method. Normally should be used only for testing purposes.