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

1.3k views Asked by At

So I've recently starting learning about tortoise-orm. But I have a question: How would I get all the data inside the SQLite database and delete all of them?

Ex Model:

from tortoise.models import Model
from tortoise import fields

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

    def __str__(self):
        return self.name
1

There are 1 answers

0
Kanishk On BEST ANSWER

you can :

  • get all the data by querying Counter.all(). Awaiting this will give you a python list of Counter objects.
  • delete the entire database by doing, await Tortoise._drop_database()

BEWARE OF DROPPING THE DATABSE, YOU WILL LOSE ALL YOU DATA

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