|
17 | 17 | )
|
18 | 18 | from arangoasync.exceptions import (
|
19 | 19 | CollectionChecksumError,
|
| 20 | + CollectionConfigureError, |
20 | 21 | CollectionPropertiesError,
|
21 | 22 | CollectionResponsibleShardError,
|
22 | 23 | CollectionRevisionError,
|
@@ -507,7 +508,71 @@ async def properties(self) -> Result[CollectionProperties]:
|
507 | 508 | def response_handler(resp: Response) -> CollectionProperties:
|
508 | 509 | if not resp.is_success:
|
509 | 510 | raise CollectionPropertiesError(resp, request)
|
510 |
| - return CollectionProperties(self._executor.deserialize(resp.raw_body)) |
| 511 | + return CollectionProperties(self.deserializer.loads(resp.raw_body)) |
| 512 | + |
| 513 | + return await self._executor.execute(request, response_handler) |
| 514 | + |
| 515 | + async def configure( |
| 516 | + self, |
| 517 | + cache_enabled: Optional[bool] = None, |
| 518 | + computed_values: Optional[Jsons] = None, |
| 519 | + replication_factor: Optional[int | str] = None, |
| 520 | + schema: Optional[Json] = None, |
| 521 | + wait_for_sync: Optional[bool] = None, |
| 522 | + write_concern: Optional[int] = None, |
| 523 | + ) -> Result[CollectionProperties]: |
| 524 | + """Changes the properties of a collection. |
| 525 | +
|
| 526 | + Only the provided attributes are updated. |
| 527 | +
|
| 528 | + Args: |
| 529 | + cache_enabled (bool | None): Whether the in-memory hash cache |
| 530 | + for documents should be enabled for this collection. |
| 531 | + computed_values (list | None): An optional list of objects, each |
| 532 | + representing a computed value. |
| 533 | + replication_factor (int | None): In a cluster, this attribute determines |
| 534 | + how many copies of each shard are kept on different DB-Servers. |
| 535 | + For SatelliteCollections, it needs to be the string "satellite". |
| 536 | + schema (dict | None): The configuration of the collection-level schema |
| 537 | + validation for documents. |
| 538 | + wait_for_sync (bool | None): If set to `True`, the data is synchronized |
| 539 | + to disk before returning from a document create, update, replace or |
| 540 | + removal operation. |
| 541 | + write_concern (int | None): Determines how many copies of each shard are |
| 542 | + required to be in sync on the different DB-Servers. |
| 543 | +
|
| 544 | + Returns: |
| 545 | + CollectionProperties: Properties. |
| 546 | +
|
| 547 | + Raises: |
| 548 | + CollectionConfigureError: If configuration fails. |
| 549 | +
|
| 550 | + References: |
| 551 | + - `change-the-properties-of-a-collection <https://docs.arangodb.com/stable/develop/http-api/collections/#change-the-properties-of-a-collection>`__ |
| 552 | + """ # noqa: E501 |
| 553 | + data: Json = {} |
| 554 | + if cache_enabled is not None: |
| 555 | + data["cacheEnabled"] = cache_enabled |
| 556 | + if computed_values is not None: |
| 557 | + data["computedValues"] = computed_values |
| 558 | + if replication_factor is not None: |
| 559 | + data["replicationFactor"] = replication_factor |
| 560 | + if schema is not None: |
| 561 | + data["schema"] = schema |
| 562 | + if wait_for_sync is not None: |
| 563 | + data["waitForSync"] = wait_for_sync |
| 564 | + if write_concern is not None: |
| 565 | + data["writeConcern"] = write_concern |
| 566 | + request = Request( |
| 567 | + method=Method.PUT, |
| 568 | + endpoint=f"/_api/collection/{self.name}/properties", |
| 569 | + data=self.serializer.dumps(data), |
| 570 | + ) |
| 571 | + |
| 572 | + def response_handler(resp: Response) -> CollectionProperties: |
| 573 | + if not resp.is_success: |
| 574 | + raise CollectionConfigureError(resp, request) |
| 575 | + return CollectionProperties(self.deserializer.loads(resp.raw_body)) |
511 | 576 |
|
512 | 577 | return await self._executor.execute(request, response_handler)
|
513 | 578 |
|
@@ -1605,9 +1670,9 @@ async def insert(
|
1605 | 1670 |
|
1606 | 1671 | def response_handler(resp: Response) -> bool | Json:
|
1607 | 1672 | if resp.is_success:
|
1608 |
| - if silent is True: |
| 1673 | + if silent: |
1609 | 1674 | return True
|
1610 |
| - return self._executor.deserialize(resp.raw_body) |
| 1675 | + return self.deserializer.loads(resp.raw_body) |
1611 | 1676 | msg: Optional[str] = None
|
1612 | 1677 | if resp.status_code == HTTP_BAD_PARAMETER:
|
1613 | 1678 | msg = (
|
@@ -1712,7 +1777,7 @@ def response_handler(resp: Response) -> bool | Json:
|
1712 | 1777 | if resp.is_success:
|
1713 | 1778 | if silent is True:
|
1714 | 1779 | return True
|
1715 |
| - return self._executor.deserialize(resp.raw_body) |
| 1780 | + return self.deserializer.loads(resp.raw_body) |
1716 | 1781 | msg: Optional[str] = None
|
1717 | 1782 | if resp.status_code == HTTP_PRECONDITION_FAILED:
|
1718 | 1783 | raise DocumentRevisionError(resp, request)
|
@@ -1802,7 +1867,7 @@ def response_handler(resp: Response) -> bool | Json:
|
1802 | 1867 | if resp.is_success:
|
1803 | 1868 | if silent is True:
|
1804 | 1869 | return True
|
1805 |
| - return self._executor.deserialize(resp.raw_body) |
| 1870 | + return self.deserializer.loads(resp.raw_body) |
1806 | 1871 | msg: Optional[str] = None
|
1807 | 1872 | if resp.status_code == HTTP_PRECONDITION_FAILED:
|
1808 | 1873 | raise DocumentRevisionError(resp, request)
|
@@ -1887,7 +1952,7 @@ def response_handler(resp: Response) -> bool | Json:
|
1887 | 1952 | if resp.is_success:
|
1888 | 1953 | if silent is True:
|
1889 | 1954 | return True
|
1890 |
| - return self._executor.deserialize(resp.raw_body) |
| 1955 | + return self.deserializer.loads(resp.raw_body) |
1891 | 1956 | msg: Optional[str] = None
|
1892 | 1957 | if resp.status_code == HTTP_PRECONDITION_FAILED:
|
1893 | 1958 | raise DocumentRevisionError(resp, request)
|
|
0 commit comments