Skip to content

Commit c90fc94

Browse files
author
Joohwan Oh
committed
Merge pull request #6 from carlverge/transaction-params
Adding params to execute_transaction
2 parents b473eac + 5df6fa8 commit c90fc94

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,25 @@ py-arango
33

44
[![Build
55
Status](https://travis-ci.org/Joowani/py-arango.svg?branch=master)](https://travis-ci.org/Joowani/py-arango)
6-
[![Documentation
7-
Status](https://readthedocs.org/projects/py-arango/badge/?version=latest)](https://readthedocs.org/projects/py-arango/?badge=latest)
86

9-
Driver for ArangoDB REST API
7+
Python Driver for ArangoDB REST API
108

119
Overview
1210
--------
1311

14-
py-arango is a Python (2.7, 3.4) driver for ArangoDB
12+
py-arango is a Python 2.7 & 3.4 driver for ArangoDB
1513
(<https://www.arangodb.com/>)
1614

17-
Documentation
18-
-------------
19-
20-
<http://py-arango.readthedocs.org/en/latest/>
21-
2215
Installation
2316
------------
2417

25-
- Stable
18+
- Stable (ArangoDB Version 2.5)
2619

2720
```bash
2821
sudo pip install py-arango
2922
```
3023

31-
- Latest
24+
- Latest (ArangoDB Version 2.5)
3225

3326
```bash
3427
git clone https://github.com/Joowani/py-arango.git

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()

0 commit comments

Comments
 (0)