Skip to content

Commit ca09add

Browse files
committed
Adding missing truncate parameters
1 parent 04151f7 commit ca09add

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

arango/collection.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -566,15 +566,29 @@ def response_handler(resp: Response) -> bool:
566566

567567
return self._execute(request, response_handler)
568568

569-
def truncate(self) -> Result[bool]:
569+
def truncate(
570+
self,
571+
sync: Optional[bool] = None,
572+
compact: Optional[bool] = None,
573+
) -> Result[bool]:
570574
"""Delete all documents in the collection.
571575
576+
:param sync: Block until deletion operation is synchronized to disk.
577+
:param compact: Whether to compact the collection after truncation.
572578
:return: True if collection was truncated successfully.
573579
:rtype: bool
574580
:raise arango.exceptions.CollectionTruncateError: If operation fails.
575581
"""
582+
params: Json = {}
583+
if sync is not None:
584+
params["waitForSync"] = sync
585+
if compact is not None:
586+
params["compact"] = compact
587+
576588
request = Request(
577-
method="put", endpoint=f"/_api/collection/{self.name}/truncate"
589+
method="put",
590+
endpoint=f"/_api/collection/{self.name}/truncate",
591+
params=params,
578592
)
579593

580594
def response_handler(resp: Response) -> bool:

tests/test_collection.py

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def test_collection_misc_methods(col, bad_col, cluster):
136136
# Test truncate collection
137137
assert col.truncate() is True
138138
assert len(col) == 0
139+
assert col.truncate(sync=True, compact=False) is True
140+
assert len(col) == 0
139141

140142
# Test truncate with bad collection
141143
with assert_raises(CollectionTruncateError) as err:

0 commit comments

Comments
 (0)