Skip to content

Commit 2eee725

Browse files
Add docs for call in transaction (#70)
Co-authored-by: Stefano Ottolenghi <stefano.ottolenghi@neo4j.com>
1 parent a78e6f5 commit 2eee725

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

modules/ROOT/pages/actions/begin-and-commit-a-transaction-in-one-request.adoc

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[[http-api-begin-and-commit-a-transaction-in-one-request]]
44
= Begin and commit a transaction in one request
55

6-
== Begin and commit request
7-
86
If there is no need to keep a transaction open across multiple HTTP requests, you can begin a transaction, execute statements, and commit within a single HTTP request.
97

108
_Example request_
@@ -50,4 +48,52 @@ _Example response_
5048
}
5149
----
5250

51+
It is also possible to send *+CALL IN TRANSACTION+* requests to this endpoint.
52+
53+
_Example request_
54+
55+
* *+POST+* +http://localhost:7474/db/neo4j/tx/commit+
56+
* *+Accept:+* +application/json;charset=UTF-8+
57+
* *+Content-Type:+* +application/json+
58+
59+
[source, JSON, role="nocopy"]
60+
----
61+
{
62+
"statements": [
63+
{
64+
"statement": "UNWIND [4, 2, 1, 0] AS i CALL { WITH i CREATE ()} IN TRANSACTIONS OF 2 ROWS RETURN i"
65+
}
66+
]
67+
}
68+
----
69+
70+
[WARNING]
71+
====
72+
If you send multiple statements (at least one being `CALL IN TRANSACTION`), and one of the normal
73+
statements fails, the `CALL IN TRANSACTION` query will *_not_* be rolled back, while the others will.
74+
In the example below, the simple `CREATE` statements would be rolled back in case of failure, but the `CALL IN TRANSACTION` would not.
75+
The final node count would thus be 4.
76+
====
5377

78+
_Example request_
79+
80+
* *+POST+* +http://localhost:7474/db/neo4j/tx/commit+
81+
* *+Accept:+* +application/json;charset=UTF-8+
82+
* *+Content-Type:+* +application/json+
83+
84+
[source, JSON, role="nocopy"]
85+
----
86+
{
87+
"statements": [
88+
{
89+
"statement": "UNWIND [4, 2, 1, 0] AS i CALL { WITH i CREATE ()} IN TRANSACTIONS OF 2 ROWS RETURN i"
90+
},
91+
{
92+
"statement": "CREATE ()"
93+
},
94+
{
95+
"statement": "CREATE ()"
96+
}
97+
]
98+
}
99+
----

0 commit comments

Comments
 (0)