Skip to content
Merged
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
10 changes: 6 additions & 4 deletions marklogic/rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,23 @@ def query(
def update(
self,
dsl: str = None,
plan: dict = None,
format: str = "json",
tx: Transaction = None,
return_response: bool = False,
**kwargs,
):
"""
Sends an update query to an endpoint at the MarkLogic rows service defined at
https://docs.marklogic.com/REST/client/row-management. Note that this feature
requires the use of MarkLogic version 11.2 or later.
https://docs.marklogic.com/REST/client/row-management. One of 'dsl' or
'plan' must be defined. This feature requires the use of MarkLogic version
11.2 or later.

For more information about Optic Update and using the Optic DSL,
see https://docs.marklogic.com/guide/app-dev/OpticAPI.
TODO - add links for Optic Update.

:param dsl: an Optic DSL query
:param plan: a serialized Optic query
:param tx: optional REST transaction in which to service this request.
:param return_response: boolean specifying if the entire original response
object should be returned (True) or if only the data should be returned (False)
Expand All @@ -106,7 +108,7 @@ def update(
"""
path = "v1/rows/update"
return self.__send_request(
path, dsl, None, None, None, None, format, tx, return_response, **kwargs
path, dsl, plan, None, None, None, format, tx, return_response, **kwargs
)

def __send_request(
Expand Down
31 changes: 31 additions & 0 deletions tests/remove-uri-plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$optic" : {
"ns" : "op",
"fn" : "operators",
"args" : [ {
"ns" : "op",
"fn" : "from-doc-uris",
"args" : [ {
"ns" : "cts",
"fn" : "document-query",
"args" : [ [ {
"ns" : "xs",
"fn" : "string",
"args" : [ "/temp/doc2.json" ]
} ] ]
}, null ]
}, {
"ns" : "op",
"fn" : "remove",
"args" : [ {
"ns" : "op",
"fn" : "col",
"args" : [ {
"ns" : "xs",
"fn" : "string",
"args" : [ "uri" ]
} ]
} ]
} ]
}
}
14 changes: 14 additions & 0 deletions tests/test_rows_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ def test_update_dsl_wrong_path(admin_client):
"Optic Update need to be run as update transaction"
in response.content.decode("utf-8")
)


def test_update_via_serialized_plan(client):
DEFAULT_PERMS = {"python-tester": ["read", "update"]}
DOC_URI = "/temp/doc2.json"
client.documents.write([Document(DOC_URI, {"doc": 1}, permissions=DEFAULT_PERMS)])
docs = client.documents.read(DOC_URI)
assert 1 == len(docs)

plan = open("tests/remove-uri-plan.json", "rb")
response = client.rows.update(plan=plan, return_response=True)
assert 200 == response.status_code
docs = client.documents.read(DOC_URI)
assert 0 == len(docs)