MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / insert

Function insert

couchbase/subdocument.py:382–408  ·  view source on GitHub ↗

Creates a :class:`.Spec` for inserting a field into the document. Failing if the field already exists at the specified path. Args: path (str): The path to the field. value (Union[JSONType, MutationMacro]): The value to insert. create_parents (bool, optional): Whether

(path,                     # type: str
           value,                    # type: Union[JSONType, MutationMacro]
           create_parents=False,     # type: Optional[bool]
           xattr=False,               # type: Optional[bool]
           **kwargs                 # type: Dict[str, Any]
           )

Source from the content-addressed store, hash-verified

380
381
382def insert(path, # type: str
383 value, # type: Union[JSONType, MutationMacro]
384 create_parents=False, # type: Optional[bool]
385 xattr=False, # type: Optional[bool]
386 **kwargs # type: Dict[str, Any]
387 ) -> Spec:
388 """Creates a :class:`.Spec` for inserting a field into the document. Failing if the field already
389 exists at the specified path.
390
391 Args:
392 path (str): The path to the field.
393 value (Union[JSONType, MutationMacro]): The value to insert.
394 create_parents (bool, optional): Whether or not the path to the field should be created
395 if it does not already exist.
396 xattr (bool, optional): Whether this operation should reference the document body or the
397 extended attributes data for the document.
398
399 Returns:
400 :class:`.Spec`: An instance of :class:`.Spec`.
401
402 """
403 expand_macros = kwargs.get('expand_macros', False)
404 if isinstance(value, MutationMacro):
405 value = value.value
406 xattr = True
407 expand_macros = True
408 return Spec(SubDocOp.DICT_ADD, path, create_parents, xattr, expand_macros, value)
409
410
411def upsert(path, # type: str

Callers

nothing calls this directly

Calls 2

SpecClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected