@@ -185,15 +185,14 @@ def closed(self):
185
185
"""
186
186
187
187
def run (self , statement , parameters = None , ** kwparameters ):
188
- """ Run a parameterised Cypher statement. If an explicit transaction
189
- has been created, the statement will be executed within that
190
- transactional context. Otherwise, this will take place within an
191
- *auto-commit transaction*.
188
+ """ Run a Cypher statement within an auto-commit transaction.
192
189
193
- :param statement: Cypher statement to execute
190
+ For usage details, see :meth:`.Transaction.run`.
191
+
192
+ :param statement: Cypher statement
194
193
:param parameters: dictionary of parameters
195
- :return: Cypher result
196
- :rtype : :class:`.StatementResult`
194
+ :param kwparameters: additional keyword parameters
195
+ :return : :class:`.StatementResult` object
197
196
"""
198
197
199
198
def fetch (self ):
@@ -258,14 +257,12 @@ class Transaction(object):
258
257
259
258
"""
260
259
261
- #: When closed , the transaction will be committed if marked as successful
262
- #: and rolled back otherwise . This attribute can be set in user code
260
+ #: When set , the transaction will be committed on close, otherwise it
261
+ #: will be rolled back. This attribute can be set in user code
263
262
#: multiple times before a transaction completes with only the final
264
263
#: value taking effect.
265
264
success = None
266
265
267
- #: Indicator to show whether the transaction has been closed, either
268
- #: with commit or rollback.
269
266
_closed = False
270
267
271
268
def __init__ (self , session , on_close ):
@@ -283,22 +280,46 @@ def __exit__(self, exc_type, exc_value, traceback):
283
280
def run (self , statement , parameters = None , ** kwparameters ):
284
281
""" Run a Cypher statement within the context of this transaction.
285
282
283
+ Cypher is typically expressed as a statement template plus a
284
+ set of named parameters. In Python, parameters may be expressed
285
+ through a dictionary of parameters, through individual parameter
286
+ arguments, or as a mixture of both. For example, the `run`
287
+ statements below are all equivalent::
288
+
289
+ >>> statement = "CREATE (a:Person {name:{name}, age:{age}})"
290
+ >>> tx.run(statement, {"name": "Alice", "age": 33})
291
+ >>> tx.run(statement, {"name": "Alice"}, age=33)
292
+ >>> tx.run(statement, name="Alice", age=33)
293
+
294
+ Parameter values can be of any type supported by the Neo4j type
295
+ system. In Python, this includes :class:`bool`, :class:`int`,
296
+ :class:`str`, :class:`list` and :class:`dict`. Note however that
297
+ :class:`list` properties must be homogenous.
298
+
286
299
:param statement: Cypher statement
287
300
:param parameters: dictionary of parameters
288
- :return: result object
301
+ :param kwparameters: additional keyword parameters
302
+ :return: :class:`.StatementResult` object
289
303
"""
290
304
if self .closed ():
291
305
raise TransactionError ("Cannot use closed transaction" )
292
306
return self .session .run (statement , parameters , ** kwparameters )
293
307
294
308
def sync (self ):
309
+ """ Send and receive all outstanding messages for this
310
+ transaction.
311
+
312
+ :raise TransactionError: if the transaction is closed
313
+ """
295
314
if self .closed ():
296
315
raise TransactionError ("Cannot use closed transaction" )
297
316
self .session .sync ()
298
317
299
318
def commit (self ):
300
319
""" Mark this transaction as successful and close in order to
301
320
trigger a COMMIT.
321
+
322
+ :raise TransactionError: if already closed
302
323
"""
303
324
if self .closed ():
304
325
raise TransactionError ("Cannot use closed transaction" )
@@ -308,6 +329,8 @@ def commit(self):
308
329
def rollback (self ):
309
330
""" Mark this transaction as unsuccessful and close in order to
310
331
trigger a ROLLBACK.
332
+
333
+ :raise TransactionError: if already closed
311
334
"""
312
335
if self .closed ():
313
336
raise TransactionError ("Cannot use closed transaction" )
@@ -326,6 +349,9 @@ def close(self):
326
349
self .on_close ()
327
350
328
351
def closed (self ):
352
+ """ Indicator to show whether the transaction has been closed.
353
+ :return: :const:`True` if closed, :const:`False` otherwise.
354
+ """
329
355
return self ._closed
330
356
331
357
0 commit comments