Skip to content

Commit 0cb9dc1

Browse files
author
Joohwan Oh
committed
Merge pull request #7 from Joowani/development
Development
2 parents 6e5f256 + 44ce964 commit 0cb9dc1

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

arango/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, protocol="http", host="localhost", port=8529,
3535
self.password = password
3636
self.db_name = db_name
3737
# self.client = SessionArangoClient() if client is None else client
38-
self.client = DefaultArangoClient() if client is None else client
38+
self.client = SessionArangoClient() if client is None else client
3939

4040
@property
4141
def url_prefix(self):

arango/database.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,9 @@ def remove_aql_function(self, name, group=None):
404404
# Transactions #
405405
################
406406

407-
# TODO deal with optional attribute "params"
408407
def execute_transaction(self, action, read_collections=None,
409-
write_collections=None, wait_for_sync=False,
410-
lock_timeout=None):
408+
write_collections=None, params=None,
409+
wait_for_sync=False, lock_timeout=None):
411410
"""Execute the transaction and return the result.
412411
413412
Setting the ``lock_timeout`` to 0 will make ArangoDB not time out
@@ -419,6 +418,8 @@ def execute_transaction(self, action, read_collections=None,
419418
:type read_collections: str or list or None
420419
:param write_collections: the collections written to
421420
:type write_collections: str or list or None
421+
:param params: Parameters for the function in action
422+
:type params: list or dict or None
422423
:param wait_for_sync: wait for the transaction to sync to disk
423424
:type wait_for_sync: bool
424425
:param lock_timeout: timeout for waiting on collection locks
@@ -433,11 +434,13 @@ def execute_transaction(self, action, read_collections=None,
433434
data["collections"]["read"] = read_collections
434435
if write_collections is not None:
435436
data["collections"]["write"] = write_collections
436-
params = {
437+
if params is not None:
438+
data["params"] = params
439+
http_params = {
437440
"waitForSync": wait_for_sync,
438441
"lockTimeout": lock_timeout,
439442
}
440-
res = self._api.post(path=path, data=data, params=params)
443+
res = self._api.post(path=path, data=data, params=http_params)
441444
if res.status_code != 200:
442445
raise TransactionExecuteError(res)
443446
return res.obj["result"]

arango/tests/test_transaction.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,33 @@ def test_execute_transaction(self):
4444
self.assertIn("doc02", self.col02)
4545

4646

47+
def test_execute_transaction_params(self):
48+
action = """
49+
function (params) {
50+
var db = require('internal').db;
51+
db.%s.save({ _key: 'doc11', val: params.val1 });
52+
db.%s.save({ _key: 'doc12', val: params.val2 });
53+
return 'success!';
54+
}
55+
""" % (self.col_name01, self.col_name02)
56+
57+
params = {"val1": 1, "val2": 2}
58+
59+
res = self.db.execute_transaction(
60+
action=action,
61+
read_collections=[self.col_name01, self.col_name02],
62+
write_collections=[self.col_name01, self.col_name02],
63+
params=params,
64+
wait_for_sync=True,
65+
lock_timeout=10000
66+
)
67+
68+
self.assertEqual(res, "success!")
69+
self.assertIn("doc11", self.col01)
70+
self.assertIn("doc12", self.col02)
71+
self.assertEqual(self.col01["doc11"]["val"], params["val1"])
72+
self.assertEqual(self.col02["doc12"]["val"], params["val2"])
73+
74+
4775
if __name__ == "__main__":
4876
unittest.main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setup(
88
name="py-arango",
99
description="Python Driver for ArangoDB",
10-
version="1.3.0",
10+
version="1.4.0",
1111
author="Joohwan Oh",
1212
author_email="joowani88@gmail.com",
1313
url="https://github.com/Joowani/py-arango",

0 commit comments

Comments
 (0)