Skip to content

Development #7

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 4 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
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="joowani88@gmail.com",
url="https://github.com/Joowani/py-arango",
Expand Down