Skip to content

Commit 1f8052b

Browse files
authored
Merge pull request #61 from marklogic/feature/update-via-plan
Can now perform update with serialized plan
2 parents 35aca13 + 6482dc3 commit 1f8052b

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

marklogic/rows.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ def query(
8383
def update(
8484
self,
8585
dsl: str = None,
86+
plan: dict = None,
8687
format: str = "json",
8788
tx: Transaction = None,
8889
return_response: bool = False,
8990
**kwargs,
9091
):
9192
"""
9293
Sends an update query to an endpoint at the MarkLogic rows service defined at
93-
https://docs.marklogic.com/REST/client/row-management. Note that this feature
94-
requires the use of MarkLogic version 11.2 or later.
94+
https://docs.marklogic.com/REST/client/row-management. One of 'dsl' or
95+
'plan' must be defined. This feature requires the use of MarkLogic version
96+
11.2 or later.
9597
9698
For more information about Optic Update and using the Optic DSL,
9799
see https://docs.marklogic.com/guide/app-dev/OpticAPI.
98-
TODO - add links for Optic Update.
99100
100101
:param dsl: an Optic DSL query
102+
:param plan: a serialized Optic query
101103
:param tx: optional REST transaction in which to service this request.
102104
:param return_response: boolean specifying if the entire original response
103105
object should be returned (True) or if only the data should be returned (False)
@@ -106,7 +108,7 @@ def update(
106108
"""
107109
path = "v1/rows/update"
108110
return self.__send_request(
109-
path, dsl, None, None, None, None, format, tx, return_response, **kwargs
111+
path, dsl, plan, None, None, None, format, tx, return_response, **kwargs
110112
)
111113

112114
def __send_request(

tests/remove-uri-plan.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$optic" : {
3+
"ns" : "op",
4+
"fn" : "operators",
5+
"args" : [ {
6+
"ns" : "op",
7+
"fn" : "from-doc-uris",
8+
"args" : [ {
9+
"ns" : "cts",
10+
"fn" : "document-query",
11+
"args" : [ [ {
12+
"ns" : "xs",
13+
"fn" : "string",
14+
"args" : [ "/temp/doc2.json" ]
15+
} ] ]
16+
}, null ]
17+
}, {
18+
"ns" : "op",
19+
"fn" : "remove",
20+
"args" : [ {
21+
"ns" : "op",
22+
"fn" : "col",
23+
"args" : [ {
24+
"ns" : "xs",
25+
"fn" : "string",
26+
"args" : [ "uri" ]
27+
} ]
28+
} ]
29+
} ]
30+
}
31+
}

tests/test_rows_update.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ def test_update_dsl_wrong_path(admin_client):
5858
"Optic Update need to be run as update transaction"
5959
in response.content.decode("utf-8")
6060
)
61+
62+
63+
def test_update_via_serialized_plan(client):
64+
DEFAULT_PERMS = {"python-tester": ["read", "update"]}
65+
DOC_URI = "/temp/doc2.json"
66+
client.documents.write([Document(DOC_URI, {"doc": 1}, permissions=DEFAULT_PERMS)])
67+
docs = client.documents.read(DOC_URI)
68+
assert 1 == len(docs)
69+
70+
plan = open("tests/remove-uri-plan.json", "rb")
71+
response = client.rows.update(plan=plan, return_response=True)
72+
assert 200 == response.status_code
73+
docs = client.documents.read(DOC_URI)
74+
assert 0 == len(docs)

0 commit comments

Comments
 (0)