Skip to content

Commit 0cd4e3c

Browse files
update api documentation (#409)
1 parent 691d016 commit 0cd4e3c

File tree

4 files changed

+72
-32
lines changed

4 files changed

+72
-32
lines changed

docs/source/api.rst

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ Sessions will often be created with some configuration settings, see :ref:`sessi
384384
Session
385385
*******
386386

387-
.. autoclass:: neo4j.Session
387+
.. autoclass:: neo4j.Session()
388388

389389
.. automethod:: close
390390

@@ -399,6 +399,13 @@ Session
399399
.. automethod:: write_transaction
400400

401401

402+
Query
403+
=====
404+
405+
.. autoclass:: neo4j.Query
406+
407+
408+
402409
.. _session-configuration-ref:
403410

404411
Session Configuration
@@ -527,18 +534,21 @@ This creates a new :class:`neo4j.Transaction` object that can be used to run Cyp
527534

528535
It also gives applications the ability to directly control `commit` and `rollback` activity.
529536

530-
.. autoclass:: neo4j.Transaction
537+
.. autoclass:: neo4j.Transaction()
531538

532539
.. automethod:: run
533540

541+
.. automethod:: close
542+
534543
.. automethod:: closed
535544

536545
.. automethod:: commit
537546

538547
.. automethod:: rollback
539548

540549
Closing an explicit transaction can either happen automatically at the end of a ``with`` block,
541-
or can be explicitly controlled through the :py:meth:`neo4j.Transaction.commit` and :py:meth:`neo4j.Transaction.rollback` methods.
550+
or can be explicitly controlled through the :py:meth:`neo4j.Transaction.commit`, :py:meth:`neo4j.Transaction.rollback` or :py:meth:`neo4j.Transaction.close` methods.
551+
542552
Explicit transactions are most useful for applications that need to distribute Cypher execution across multiple functions for the same transaction.
543553

544554
.. code-block:: python
@@ -607,7 +617,7 @@ Results also contain a buffer that automatically stores unconsumed records when
607617

608618
A :class:`neo4j.Result` is attached to an active connection, through a :class:`neo4j.Session`, until all its content has been buffered or consumed.
609619

610-
.. autoclass:: neo4j.Result
620+
.. autoclass:: neo4j.Result()
611621

612622
.. describe:: iter(result)
613623

@@ -624,10 +634,13 @@ A :class:`neo4j.Result` is attached to an active connection, through a :class:`n
624634
**This is experimental.**
625635

626636

637+
See https://neo4j.com/docs/driver-manual/current/cypher-workflow/#driver-type-mapping for more about type mapping.
638+
639+
627640
Graph
628641
=====
629642

630-
.. autoclass:: neo4j.graph.Graph
643+
.. autoclass:: neo4j.graph.Graph()
631644

632645
A local, self-contained graph object that acts as a container for :class:`.Node` and :class:`neo4j.Relationship` instances.
633646
This is typically obtained via the :meth:`neo4j.Result.graph` method.
@@ -645,7 +658,7 @@ Graph
645658
Record
646659
******
647660

648-
.. autoclass:: neo4j.Record
661+
.. autoclass:: neo4j.Record()
649662

650663
A :class:`neo4j.Record` is an immutable ordered collection of key-value
651664
pairs. It is generally closer to a :py:class:`namedtuple` than to an
@@ -710,20 +723,20 @@ Record
710723
ResultSummary
711724
*************
712725

713-
.. autoclass:: neo4j.ResultSummary
726+
.. autoclass:: neo4j.ResultSummary()
714727
:members:
715728

716729
SummaryCounters
717730
===============
718731

719-
.. autoclass:: neo4j.SummaryCounters
732+
.. autoclass:: neo4j.SummaryCounters()
720733
:members:
721734

722735

723736
ServerInfo
724737
==========
725738

726-
.. autoclass:: neo4j.ServerInfo
739+
.. autoclass:: neo4j.ServerInfo()
727740
:members:
728741

729742

@@ -794,7 +807,7 @@ Path :class:`neo4j.graph.Path`
794807
Node
795808
====
796809

797-
.. autoclass:: neo4j.graph.Node
810+
.. autoclass:: neo4j.graph.Node()
798811

799812
.. describe:: node == other
800813

@@ -843,7 +856,7 @@ Node
843856
Relationship
844857
============
845858

846-
.. autoclass:: neo4j.graph.Relationship
859+
.. autoclass:: neo4j.graph.Relationship()
847860

848861
.. describe:: relationship == other
849862

@@ -904,7 +917,7 @@ Relationship
904917
Path
905918
====
906919

907-
.. autoclass:: neo4j.graph.Path
920+
.. autoclass:: neo4j.graph.Path()
908921

909922
.. describe:: path == other
910923

docs/source/breaking_changes.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Introduced :class:`neo4j.Bookmark`
5050
Exceptions Changes
5151
==================
5252

53-
The exceptions in :code:`neo4j.exceptions` have been updated and there are internal exceptions starting with the naming :code:`Bolt` that should be propagated into the exceptions API.
53+
The exceptions in :code:`neo4j.exceptions` has been updated and there are internal exceptions starting with the naming :code:`Bolt` that should be propagated into the exceptions API.
5454

5555
See :ref:`errors-ref` for more about errors.
5656

@@ -83,7 +83,24 @@ Argument Renaming Changes
8383
API Changes
8484
=========================
8585

86-
* :code:`Result.summary()` have been replaced with :code:`Result.consume()`, this behaviour is to consume all remaining records in the buffer and returns the ResultSummary.
86+
* :code:`Result.summary()` has been replaced with :code:`Result.consume()`, this behaviour is to consume all remaining records in the buffer and returns the ResultSummary.
87+
88+
* :code:`Transaction.sync()` has been removed. Use :code:`Result.consume()` if the behaviour is to exhaust the result object.
89+
90+
* :code:`Transaction.success` has been removed.
91+
92+
* :code:`Transaction.close()` behaviour changed. Will now only perform rollback if no commit have been performed.
93+
94+
* :code:`Session.sync()` has been removed. Use :code:`Result.consume()` if the behaviour is to exhaust the result object.
95+
96+
* :code:`Session.detach()` has been removed. Use :code:`Result.consume()` if the behaviour is to exhaust the result object.
97+
98+
* :code:`Session.next_bookmarks()` has been removed.
99+
100+
* :code:`Session.has_transaction()` has been removed.
101+
102+
* :code:`Session.closed()` has been removed.
103+
87104
* :code:`Session.write_transaction` and :code:`Session.read_transaction` will start the retry timer after the first failed attempt.
88105

89106
Dependency Changes

neo4j/work/simple.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,13 @@ def run(self, query, parameters=None, **kwparameters):
186186
187187
For more usage details, see :meth:`.Transaction.run`.
188188
189-
:param query: Cypher query
189+
:param query: cypher query
190+
:type query: str, neo4j.Query
190191
:param parameters: dictionary of parameters
192+
:type parameters: dict
191193
:param kwparameters: additional keyword parameters
192-
:returns: :class:`neo4j.Result` object
194+
:returns: a new :class:`neo4j.Result` object
195+
:type: :class:`neo4j.Result`
193196
"""
194197
if not query:
195198
raise ValueError("Cannot run an empty query")
@@ -383,11 +386,11 @@ class Query:
383386
""" Create a new query.
384387
385388
:param text: The query text.
386-
:type str:
389+
:type text: str
387390
:param metadata: metadata attached to the query.
388-
:type dict:
391+
:type metadata: dict
389392
:param timeout: seconds.
390-
:type int:
393+
:type timeout: int
391394
"""
392395
def __init__(self, text, metadata=None, timeout=None):
393396
self.text = text

neo4j/work/transaction.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ def run(self, query, parameters=None, **kwparameters):
9292
:class:`str`, :class:`list` and :class:`dict`. Note however that
9393
:class:`list` properties must be homogenous.
9494
95-
:param query: template Cypher query
95+
:param query: cypher query
96+
:type query: str
9697
:param parameters: dictionary of parameters
98+
:type parameters: dict
9799
:param kwparameters: additional keyword parameters
98-
:returns: :class:`neo4j.Result` object
99-
:raise TransactionError: if the transaction is closed
100+
:returns: a new :class:`neo4j.Result` object
101+
:rtype: :class:`neo4j.Result`
102+
:raise TransactionError: if the transaction is already closed
100103
"""
101104
from neo4j.work.simple import Query
102105
if isinstance(query, Query):
@@ -117,11 +120,12 @@ def run(self, query, parameters=None, **kwparameters):
117120
return result
118121

119122
def commit(self):
120-
""" Mark this transaction as successful and close in order to
121-
trigger a COMMIT. This is functionally equivalent to::
123+
"""Mark this transaction as successful and close in order to trigger a COMMIT.
122124
123-
:raise TransactionError: if already closed
125+
:raise TransactionError: if the transaction is already closed
124126
"""
127+
if self._closed:
128+
raise TransactionError("Transaction closed")
125129
metadata = {}
126130
self._consume_results() # DISCARD pending records then do a commit.
127131
try:
@@ -139,11 +143,12 @@ def commit(self):
139143
return self._bookmark
140144

141145
def rollback(self):
142-
""" Mark this transaction as unsuccessful and close in order to
143-
trigger a ROLLBACK. This is functionally equivalent to::
146+
"""Mark this transaction as unsuccessful and close in order to trigger a ROLLBACK.
144147
145-
:raise TransactionError: if already closed
148+
:raise TransactionError: if the transaction is already closed
146149
"""
150+
if self._closed:
151+
raise TransactionError("Transaction closed")
147152
metadata = {}
148153
if not self._connection._is_reset:
149154
self._consume_results() # DISCARD pending records then do a rollback.
@@ -154,16 +159,18 @@ def rollback(self):
154159
self._on_closed()
155160

156161
def close(self):
157-
""" Close this transaction, triggering either a ROLLBACK if not committed.
162+
"""Close this transaction, triggering a ROLLBACK if not closed.
158163
159-
:raise TransactionError: if already closed
164+
:raise TransactionError: if the transaction could not perform a ROLLBACK.
160165
"""
161166
if self._closed:
162167
return
163168
self.rollback()
164169

165170
def closed(self):
166-
""" Indicator to show whether the transaction has been closed.
167-
:returns: :const:`True` if closed, :const:`False` otherwise.
171+
"""Indicator to show whether the transaction has been closed.
172+
173+
:return: :const:`True` if closed, :const:`False` otherwise.
174+
:rtype: bool
168175
"""
169176
return self._closed

0 commit comments

Comments
 (0)