Skip to content

Commit

Permalink
Merge pull request #7 from Joowani/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Joohwan Oh committed Jun 16, 2015
2 parents 6e5f256 + 44ce964 commit 0cb9dc1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion arango/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, protocol="http", host="localhost", port=8529,
self.password = password
self.db_name = db_name
# self.client = SessionArangoClient() if client is None else client
self.client = DefaultArangoClient() if client is None else client
self.client = SessionArangoClient() if client is None else client

@property
def url_prefix(self):
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()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name="py-arango",
description="Python Driver for ArangoDB",
version="1.3.0",
version="1.4.0",
author="Joohwan Oh",
author_email="[email protected]",
url="https://github.com/Joowani/py-arango",
Expand Down

0 comments on commit 0cb9dc1

Please sign in to comment.