from typing import Optional
from tortoise.models import Model
from tortoise import BaseDBAsyncClient
class MyBaseModel(Model):
@classmethod
async def truncate_model(cls, using_db: Optional[BaseDBAsyncClient] = None):
db = using_db or cls._choose_db(True)
return await db.execute_query('TRUNCATE TABLE {}'.format(cls._meta.db_table))
The third way seems to solve my problem elegantly, wondering if this functionality can be built in? or he has some safety hazard?
I need the operation to truncate the table, I can't find it in the documentation
I found related method in django
1.
2.
3.
The third way seems to solve my problem elegantly, wondering if this functionality can be built in? or he has some safety hazard?