API
Document Client
Note
Although DocumentClient
is implemented in the documentapi.api
module,
documentapi.api
is not meant to be imported directly because it contains helper functions.
Please import DocumentClient
from the documentapi
package
as shown in the Cookbook.
- class documentapi.api.DocumentClient(client: Client)
Client to run JSON queries
- append(key: Tuple[str, str, Union[str, int, bytearray]], binName: str, jsonPath: str, obj: Any, writePolicy: Optional[Dict[str, Any]] = None)
Append an object to a list in a JSON document using JSON path.
- Parameters
key (tuple) – the key of the record
binName (str) – the name of the bin containing the JSON document
jsonPath (str) – JSON path ending with a list
writePolicy (dict) – the write policy for operate() operation
- Raises
- Raises
- Raises
- delete(key: Tuple[str, str, Union[str, int, bytearray]], binName: str, jsonPath: str, writePolicy: Optional[Dict[str, Any]] = None)
Delete an object in a JSON document using JSON path.
Deleting the root element causes the bin to contain an empty dictionary.
- Parameters
key (tuple) – the key of the record
binName (str) – the name of the bin containing the JSON document
jsonPath (str) – JSON path of object to delete
writePolicy (dict) – the write policy for operate() operation
- Raises
- Raises
- Raises
- get(key: Tuple[str, str, Union[str, int, bytearray]], binName: str, jsonPath: str, readPolicy: Optional[Dict[str, Any]] = None) Any
Get object(s) from a JSON document using JSON path.
If multiple objects are matched, they will be returned as a
list
. A list of results does not have a guaranteed order.Otherwise, the object itself is returned.
- Parameters
key (tuple) – the key of the record
binName (str) – the name of the bin containing the JSON document
jsonPath (str) – JSON path to retrieve the object
readPolicy (dict) – the read policy for get() operation
- Returns
Any
- Raises
- Raises
- Raises
- put(key: Tuple[str, str, Union[str, int, bytearray]], binName: str, jsonPath: str, obj: Any, writePolicy: Optional[Dict[str, Any]] = None)
Put an object into a JSON document using JSON path.
- Parameters
key (tuple) – the key of the record
binName (str) – the name of the bin containing the JSON document
jsonPath (str) – JSON path location to store the object
writePolicy (dict) – the write policy for put() operation
- Raises
- Raises
- Raises
Exceptions
- exception documentapi.exception.JSONNotFoundError(jsonPath)
This is thrown when an object can’t be found with the JSON path.
- exception documentapi.exception.JsonPathMissingRootError(jsonPath)
This is thrown when the JSON path doesn’t start with a
$
.
- exception documentapi.exception.JsonPathParseError(jsonPath)
This is thrown when the JSON path has invalid syntax.