From c414ddee54a401e70f14a06e5456c09a3a7a9b93 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sun, 2 Mar 2025 10:30:17 -0800 Subject: feat(db): add truncateTable method Signed-off-by: Varun Patil --- lib/private/DB/Connection.php | 13 +++++++++++++ lib/private/DB/ConnectionAdapter.php | 8 ++++++++ 2 files changed, 21 insertions(+) (limited to 'lib/private') diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 3fddfdcb094..eecf83ace95 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -698,6 +698,19 @@ class Connection extends PrimaryReadReplicaConnection { } } + /** + * Truncate a table data if it exists + * + * @param string $table table name without the prefix + * @param bool $cascade whether to truncate cascading + * + * @throws Exception + */ + public function truncateTable(string $table, bool $cascade) { + $this->executeStatement($this->getDatabasePlatform() + ->getTruncateTableSQL($this->tablePrefix . trim($table), $cascade)); + } + /** * Check if a table exists * diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php index 2baeda9cfb7..ba3bf90c2e8 100644 --- a/lib/private/DB/ConnectionAdapter.php +++ b/lib/private/DB/ConnectionAdapter.php @@ -189,6 +189,14 @@ class ConnectionAdapter implements IDBConnection { } } + public function truncateTable(string $table, bool $cascade): void { + try { + $this->inner->truncateTable($table, $cascade); + } catch (Exception $e) { + throw DbalException::wrap($e); + } + } + public function tableExists(string $table): bool { try { return $this->inner->tableExists($table); -- cgit v1.2.3