Skip to content

Adding params to execute_transaction #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2015
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
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,25 @@ py-arango

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

Driver for ArangoDB REST API
Python Driver for ArangoDB REST API

Overview
--------

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

Documentation
-------------

<http://py-arango.readthedocs.org/en/latest/>

Installation
------------

- Stable
- Stable (ArangoDB Version 2.5)

```bash
sudo pip install py-arango
```

- Latest
- Latest (ArangoDB Version 2.5)

```bash
git clone https://github.com/Joowani/py-arango.git
Expand Down
13 changes: 8 additions & 5 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,9 @@ def remove_aql_function(self, name, group=None):
# Transactions #
################

# TODO deal with optional attribute "params"
def execute_transaction(self, action, read_collections=None,
write_collections=None, wait_for_sync=False,
lock_timeout=None):
write_collections=None, params=None,
wait_for_sync=False, lock_timeout=None):
"""Execute the transaction and return the result.

Setting the ``lock_timeout`` to 0 will make ArangoDB not time out
Expand All @@ -419,6 +418,8 @@ def execute_transaction(self, action, read_collections=None,
:type read_collections: str or list or None
:param write_collections: the collections written to
:type write_collections: str or list or None
:param params: Parameters for the function in action
:type params: list or dict or None
:param wait_for_sync: wait for the transaction to sync to disk
:type wait_for_sync: bool
:param lock_timeout: timeout for waiting on collection locks
Expand All @@ -433,11 +434,13 @@ def execute_transaction(self, action, read_collections=None,
data["collections"]["read"] = read_collections
if write_collections is not None:
data["collections"]["write"] = write_collections
params = {
if params is not None:
data["params"] = params
http_params = {
"waitForSync": wait_for_sync,
"lockTimeout": lock_timeout,
}
res = self._api.post(path=path, data=data, params=params)
res = self._api.post(path=path, data=data, params=http_params)
if res.status_code != 200:
raise TransactionExecuteError(res)
return res.obj["result"]
Expand Down
28 changes: 28 additions & 0 deletions arango/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,33 @@ def test_execute_transaction(self):
self.assertIn("doc02", self.col02)


def test_execute_transaction_params(self):
action = """
function (params) {
var db = require('internal').db;
db.%s.save({ _key: 'doc11', val: params.val1 });
db.%s.save({ _key: 'doc12', val: params.val2 });
return 'success!';
}
""" % (self.col_name01, self.col_name02)

params = {"val1": 1, "val2": 2}

res = self.db.execute_transaction(
action=action,
read_collections=[self.col_name01, self.col_name02],
write_collections=[self.col_name01, self.col_name02],
params=params,
wait_for_sync=True,
lock_timeout=10000
)

self.assertEqual(res, "success!")
self.assertIn("doc11", self.col01)
self.assertIn("doc12", self.col02)
self.assertEqual(self.col01["doc11"]["val"], params["val1"])
self.assertEqual(self.col02["doc12"]["val"], params["val2"])


if __name__ == "__main__":
unittest.main()