Skip to content

Commit d1b3480

Browse files
authored
Merge pull request #57 from BillFarber/feature/rowsUpdate
DEVEXP-639: Submit Optic Update DSL plan via Python Client
2 parents b055cc5 + fada978 commit d1b3480

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

marklogic/rows.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,61 @@ def query(
6767
not 2xx, then the entire response is always returned.
6868
"""
6969
path = "v1/rows/graphql" if graphql else "v1/rows"
70+
return self.__send_request(
71+
path,
72+
dsl,
73+
plan,
74+
sql,
75+
sparql,
76+
graphql,
77+
format,
78+
tx,
79+
return_response,
80+
**kwargs,
81+
)
82+
83+
def update(
84+
self,
85+
dsl: str = None,
86+
format: str = "json",
87+
tx: Transaction = None,
88+
return_response: bool = False,
89+
**kwargs,
90+
):
91+
"""
92+
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.
95+
96+
For more information about Optic Update and using the Optic DSL,
97+
see https://docs.marklogic.com/guide/app-dev/OpticAPI.
98+
TODO - add links for Optic Update.
99+
100+
:param dsl: an Optic DSL query
101+
:param tx: optional REST transaction in which to service this request.
102+
:param return_response: boolean specifying if the entire original response
103+
object should be returned (True) or if only the data should be returned (False)
104+
upon a success (2xx) response. Note that if the status code of the response is
105+
not 2xx, then the entire response is always returned.
106+
"""
107+
path = "v1/rows/update"
108+
return self.__send_request(
109+
path, dsl, None, None, None, None, format, tx, return_response, **kwargs
110+
)
111+
112+
def __send_request(
113+
self,
114+
path: str = None,
115+
dsl: str = None,
116+
plan: dict = None,
117+
sql: str = None,
118+
sparql: str = None,
119+
graphql: str = None,
120+
format: str = "json",
121+
tx: Transaction = None,
122+
return_response: bool = False,
123+
**kwargs,
124+
):
70125
headers = kwargs.pop("headers", {})
71126
data = None
72127
if graphql:

tests/test_rows_update.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from marklogic.documents import DefaultMetadata, Document
2+
3+
4+
def test_update_dsl_remove(admin_client):
5+
DEFAULT_PERMS = {"python-tester": ["read", "update"]}
6+
DOC_URI = "/temp/doc1.json"
7+
response = admin_client.documents.write(
8+
[Document(DOC_URI, {"doc": 1}, permissions=DEFAULT_PERMS)]
9+
)
10+
11+
update_query_remove = 'op.fromDocUris("' + DOC_URI + '").lockForUpdate().remove()'
12+
response = admin_client.rows.update(update_query_remove, return_response=True)
13+
assert 200 == response.status_code
14+
15+
docs = admin_client.documents.read([DOC_URI])
16+
assert 0 == len(docs)
17+
18+
19+
def test_update_dsl_wrong_path(admin_client):
20+
DEFAULT_PERMS = {"python-tester": ["read", "update"]}
21+
DOC_URI = "/temp/doc1.json"
22+
response = admin_client.documents.write(
23+
[Document(DOC_URI, {"doc": 1}, permissions=DEFAULT_PERMS)]
24+
)
25+
26+
update_query_remove = 'op.fromDocUris("' + DOC_URI + '").lockForUpdate().remove()'
27+
response = admin_client.rows.query(update_query_remove, return_response=True)
28+
assert 400 == response.status_code
29+
assert (
30+
"Optic Update need to be run as update transaction"
31+
in response.content.decode("utf-8")
32+
)

0 commit comments

Comments
 (0)