Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/insert_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def parameter_to_document(param):
return {'@type': 'Parameter', 'type': param.type, 'name': param.name, 'summary': "\n".join(param.desc)}

classes_to_scan = ['Client']#, 'WOQLQuery']
classes_to_scan = ['Client', 'WOQLQuery']
classes = []

for name, obj in inspect.getmembers(terminusdb_client):
Expand Down
2 changes: 1 addition & 1 deletion terminusdb_client/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "terminusdb-client"
__description__ = "TerminusDB client library for accessing the Terminus DB API"
__url__ = ""
__version__ = "11.1.0"
__version__ = "12.0.5"
__build__ = 00
__author__ = "TerminusDB group"
__author_email__ = "team@terminusdb.com"
Expand Down
38 changes: 36 additions & 2 deletions terminusdb_client/client/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ def insert_document(
last_data_version: Optional[str] = None,
compress: Union[str, int] = 1024,
raw_json: bool = False,
merge_repeats: bool = False,
overwrite: bool = False,
) -> None:
"""Inserts the specified document(s)

Expand All @@ -1499,6 +1501,10 @@ def insert_document(
If it is an integer, size of the data larger than this (in bytes) will be compress with gzip in the request (assume encoding as UTF-8, 0 = always compress). If it is `never` it will never compress the data.
raw_json : bool
Update as raw json
merge_repeats : bool
If True, duplicate document IDs in the same request are silently accepted instead of causing an error.
overwrite : bool
If True, existing documents with the same ID will be overwritten instead of causing an error. This enables upsert behavior.

Raises
------
Expand All @@ -1518,6 +1524,8 @@ def insert_document(
else:
params["full_replace"] = "false"
params["raw_json"] = "true" if raw_json else "false"
params["merge_repeats"] = "true" if merge_repeats else "false"
params["overwrite"] = "true" if overwrite else "false"

headers = self._default_headers.copy()
if last_data_version is not None:
Expand Down Expand Up @@ -1587,6 +1595,7 @@ def replace_document(
compress: Union[str, int] = 1024,
create: bool = False,
raw_json: bool = False,
merge_repeats: bool = False,
) -> dict:
"""Updates the specified document(s)

Expand All @@ -1606,6 +1615,8 @@ def replace_document(
Create the document if it does not yet exist.
raw_json : bool
Update as raw json
merge_repeats : bool
If True, duplicate document IDs in the same request are silently accepted instead of causing an error.

Raises
------
Expand All @@ -1617,6 +1628,7 @@ def replace_document(
params["graph_type"] = graph_type
params["create"] = "true" if create else "false"
params["raw_json"] = "true" if raw_json else "false"
params["merge_repeats"] = "true" if merge_repeats else "false"

headers = self._default_headers.copy()
if last_data_version is not None:
Expand Down Expand Up @@ -1667,6 +1679,7 @@ def update_document(
commit_msg: Optional[str] = None,
last_data_version: Optional[str] = None,
compress: Union[str, int] = 1024,
merge_repeats: bool = False,
) -> None:
"""Updates the specified document(s). Add the document if not existed.

Expand All @@ -1682,14 +1695,17 @@ def update_document(
Last version before the update, used to check if the document has been changed unknowingly
compress : str or int
If it is an integer, size of the data larger than this (in bytes) will be compress with gzip in the request (assume encoding as UTF-8, 0 = always compress). If it is `never` it will never compress the data.
merge_repeats : bool
If True, duplicate document IDs in the same request are silently accepted instead of causing an error.

Raises
------
InterfaceError
if the client does not connect to a database
"""
self.replace_document(
document, graph_type, commit_msg, last_data_version, compress, True
document, graph_type, commit_msg, last_data_version, compress, True,
merge_repeats=merge_repeats,
)

def delete_document(
Expand Down Expand Up @@ -2379,7 +2395,9 @@ def diff_object(self, before_object, after_object):
)
)

def diff_version(self, before_version, after_version):
def diff_version(
self, before_version, after_version, unfold: bool = True
):
"""Diff two different versions. Can either be a branch or a commit

Parameters
Expand All @@ -2388,6 +2406,10 @@ def diff_version(self, before_version, after_version):
Commit or branch of the before version to compare
after_version : string
Commit or branch of the after version to compare
unfold : bool, optional
Expand subdocuments inline when retrieving documents from the
specified versions. Defaults to ``True``; set to ``False`` to
compare folded documents by reference.
"""
self._check_connection(check_db=False)
return json.loads(
Expand All @@ -2398,6 +2420,7 @@ def diff_version(self, before_version, after_version):
json={
"before_data_version": before_version,
"after_data_version": after_version,
"unfold": unfold,
},
auth=self._auth(),
)
Expand All @@ -2423,13 +2446,21 @@ def diff(
List["DocumentTemplate"], # noqa:F821
],
document_id: Union[str, None] = None,
unfold: bool = True,
):
"""DEPRECATED

Perform diff on 2 set of document(s), result in a Patch object.

Do not connect when using public API.

Parameters
----------
unfold : bool, optional
Expand subdocuments inline when retrieving documents from commits
or branches. Only used when ``before`` or ``after`` is a version
reference. Defaults to ``True``.

Returns
-------
obj
Expand Down Expand Up @@ -2461,6 +2492,9 @@ def diff(
raise ValueError(
"`document_id` can only be used in conjusction with a data version or commit ID as `before`, not a document object"
)
if isinstance(before, str) or isinstance(after, str):
request_dict["unfold"] = unfold

if self._connected:
result = _finish_response(
self._session.post(
Expand Down
Loading