Creates a :class:`.Spec` for incrementing the value of a field in a document. Args: path (str): The path to the field. delta (int): The value to increment from the document. xattr (bool, optional): Whether this operation should reference the document body or the
(path, # type: str
delta, # type: int
xattr=False, # type: Optional[bool]
create_parents=False # type: Optional[bool]
)
| 622 | |
| 623 | |
| 624 | def increment(path, # type: str |
| 625 | delta, # type: int |
| 626 | xattr=False, # type: Optional[bool] |
| 627 | create_parents=False # type: Optional[bool] |
| 628 | ) -> Spec: |
| 629 | """Creates a :class:`.Spec` for incrementing the value of a field in a document. |
| 630 | |
| 631 | Args: |
| 632 | path (str): The path to the field. |
| 633 | delta (int): The value to increment from the document. |
| 634 | xattr (bool, optional): Whether this operation should reference the document body or the |
| 635 | extended attributes data for the document. |
| 636 | create_parents (bool, optional): Whether or not the path to the field should be created |
| 637 | if it does not already exist. |
| 638 | |
| 639 | Returns: |
| 640 | :class:`.Spec`: An instance of :class:`.Spec`. |
| 641 | |
| 642 | |
| 643 | Raises: |
| 644 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the delta arugment is not >= 0 or not |
| 645 | of type int. |
| 646 | """ |
| 647 | if not isinstance(delta, int): |
| 648 | raise InvalidArgumentException("Delta must be integer") |
| 649 | if delta <= 0: |
| 650 | raise InvalidArgumentException( |
| 651 | "Delta must be integer greater than or equal to 0") |
| 652 | |
| 653 | return Spec(SubDocOp.COUNTER, path, create_parents, xattr, False, delta) |
| 654 | |
| 655 | |
| 656 | def decrement(path, # type: str |
no test coverage detected