test clear package api
Some checks failed
Build and Deploy MITM Webserver / build (push) Has been cancelled
Some checks failed
Build and Deploy MITM Webserver / build (push) Has been cancelled
This commit is contained in:
@@ -156,3 +156,26 @@ class DatabasePool:
|
||||
out.append(d)
|
||||
logger.exception(d)
|
||||
return out
|
||||
|
||||
async def clear_all_packets(self, reset_identity: bool = True) -> bool:
|
||||
"""
|
||||
Deletes all rows from the `packets` table.
|
||||
|
||||
If reset_identity is True, the auto-increment ID counter is reset to 1.
|
||||
Returns True if successful, False otherwise.
|
||||
"""
|
||||
if self._pool is None:
|
||||
await self.init_pool()
|
||||
|
||||
# TRUNCATE is faster than DELETE and resets the identity counter
|
||||
restart_clause = "RESTART IDENTITY" if reset_identity else ""
|
||||
query = f"TRUNCATE TABLE packets {restart_clause};"
|
||||
|
||||
try:
|
||||
async with self._pool.acquire() as conn:
|
||||
await conn.execute(query)
|
||||
logger.info("Successfully cleared all packets from the database (reset_id=%s)", reset_identity)
|
||||
return True
|
||||
except Exception:
|
||||
logger.exception("Failed to clear packets table")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user