Skip to content

Collection Maintenance #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding missing truncate parameters
  • Loading branch information
apetenchea committed Mar 20, 2025
commit ca09addfb0a0228c87a37e08e0287b3bc693378c
18 changes: 16 additions & 2 deletions arango/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,15 +566,29 @@ def response_handler(resp: Response) -> bool:

return self._execute(request, response_handler)

def truncate(self) -> Result[bool]:
def truncate(
self,
sync: Optional[bool] = None,
compact: Optional[bool] = None,
) -> Result[bool]:
"""Delete all documents in the collection.

:param sync: Block until deletion operation is synchronized to disk.
:param compact: Whether to compact the collection after truncation.
:return: True if collection was truncated successfully.
:rtype: bool
:raise arango.exceptions.CollectionTruncateError: If operation fails.
"""
params: Json = {}
if sync is not None:
params["waitForSync"] = sync
if compact is not None:
params["compact"] = compact

request = Request(
method="put", endpoint=f"/_api/collection/{self.name}/truncate"
method="put",
endpoint=f"/_api/collection/{self.name}/truncate",
params=params,
)

def response_handler(resp: Response) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def test_collection_misc_methods(col, bad_col, cluster):
# Test truncate collection
assert col.truncate() is True
assert len(col) == 0
assert col.truncate(sync=True, compact=False) is True
assert len(col) == 0

# Test truncate with bad collection
with assert_raises(CollectionTruncateError) as err:
Expand Down