Skip to content

Commit 0961e25

Browse files
committed
Result and sync docs
1 parent a751903 commit 0961e25

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

docs/source/session.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Cypher Sessions
1010
:members:
1111

1212
.. autoclass:: neo4j.v1.StatementResult
13-
:members:
13+
:members: buffer, consume, fetch, keys, online, peek, records, single, summary
1414

1515
.. autoclass:: neo4j.v1.Record
1616
:members:

neo4j/v1/api.py

+52-21
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def session(self, access_mode=None):
122122
within a single thread.
123123
124124
:param access_mode:
125-
:return: new :class:`.Session` object
125+
:returns: new :class:`.Session` object
126126
"""
127127
pass
128128

@@ -181,31 +181,34 @@ def close(self):
181181
def closed(self):
182182
""" Indicator for whether or not this session has been closed.
183183
184-
:return: :const:`True` if closed, :const:`False` otherwise.
184+
:returns: :const:`True` if closed, :const:`False` otherwise.
185185
"""
186186

187187
def run(self, statement, parameters=None, **kwparameters):
188188
""" Run a Cypher statement within an auto-commit transaction.
189+
Note that the statement is only passed to the server lazily,
190+
when the result is consumed. To force the statement to be sent to
191+
the server, use the :meth:`.Session.sync` method.
189192
190193
For usage details, see :meth:`.Transaction.run`.
191194
192195
:param statement: Cypher statement
193196
:param parameters: dictionary of parameters
194197
:param kwparameters: additional keyword parameters
195-
:return: :class:`.StatementResult` object
198+
:returns: :class:`.StatementResult` object
196199
"""
197200

198201
def fetch(self):
199202
""" Fetch the next message if available.
200203
201-
:return: The number of messages fetched (zero or one)
204+
:returns: The number of messages fetched (zero or one)
202205
"""
203206
return 0
204207

205208
def sync(self):
206209
""" Carry out a full send and receive.
207210
208-
:return: Total number of records received
211+
:returns: Total number of records received
209212
"""
210213
return 0
211214

@@ -214,7 +217,7 @@ def begin_transaction(self, bookmark=None):
214217
215218
:param bookmark: a bookmark to which the server should
216219
synchronise before beginning the transaction
217-
:return: new :class:`.Transaction` instance.
220+
:returns: new :class:`.Transaction` instance.
218221
:raise: :class:`.TransactionError` if a transaction is already open
219222
"""
220223
if self.transaction:
@@ -229,7 +232,7 @@ def clear_transaction():
229232
def commit_transaction(self):
230233
""" Commit the current transaction.
231234
232-
:return: the bookmark returned from the server, if any
235+
:returns: the bookmark returned from the server, if any
233236
:raise: :class:`.TransactionError` if no transaction is currently open
234237
"""
235238
if not self.transaction:
@@ -279,6 +282,9 @@ def __exit__(self, exc_type, exc_value, traceback):
279282

280283
def run(self, statement, parameters=None, **kwparameters):
281284
""" Run a Cypher statement within the context of this transaction.
285+
Note that the statement is only passed to the server lazily,
286+
when the result is consumed. To force the statement to be sent to
287+
the server, use the :meth:`.Transaction.sync` method.
282288
283289
Cypher is typically expressed as a statement template plus a
284290
set of named parameters. In Python, parameters may be expressed
@@ -299,7 +305,7 @@ def run(self, statement, parameters=None, **kwparameters):
299305
:param statement: Cypher statement
300306
:param parameters: dictionary of parameters
301307
:param kwparameters: additional keyword parameters
302-
:return: :class:`.StatementResult` object
308+
:returns: :class:`.StatementResult` object
303309
"""
304310
if self.closed():
305311
raise TransactionError("Cannot use closed transaction")
@@ -350,13 +356,15 @@ def close(self):
350356

351357
def closed(self):
352358
""" Indicator to show whether the transaction has been closed.
353-
:return: :const:`True` if closed, :const:`False` otherwise.
359+
:returns: :const:`True` if closed, :const:`False` otherwise.
354360
"""
355361
return self._closed
356362

357363

358364
class StatementResult(object):
359-
""" A handler for the result of Cypher statement execution.
365+
""" A handler for the result of Cypher statement execution. Instances
366+
of this class are typically constructed and returned by
367+
:meth:`.Session.run` and :meth:`.Transaction.run`.
360368
"""
361369

362370
#: The statement text that was executed to produce this result.
@@ -385,36 +393,44 @@ def __iter__(self):
385393
return self.records()
386394

387395
def online(self):
388-
""" True if this result is still attached to an active Session.
396+
""" Indicator for whether or not this result is still attached to
397+
a :class:`.Session`.
398+
399+
:returns: :const:`True` if still attached, :const:`False` otherwise
389400
"""
390401
return self._session and not self._session.closed()
391402

392403
def fetch(self):
393-
""" Fetch another record, if available. Return the number fetched.
404+
""" Fetch another record, if available.
405+
406+
:returns: number of records fetched (zero or one)
394407
"""
395408
if self.online():
396409
return self._session.fetch()
397410
else:
398411
return 0
399412

400413
def buffer(self):
401-
""" Fetch the remainder of the result from the network and buffer
402-
it for future consumption.
414+
""" Fetch the remainder of this result from the network and buffer
415+
it. On return from this method, the result will no longer be
416+
:meth:`.online`.
403417
"""
404418
while self.online():
405419
self.fetch()
406420

407421
def keys(self):
408-
""" Return the keys for the records.
422+
""" The keys for the records in this result.
423+
424+
:returns: tuple of key names
409425
"""
410426
while self._keys is None and self.online():
411427
self.fetch()
412428
return self._keys
413429

414430
def records(self):
415-
""" Yield records.
431+
""" Generator for records obtained from this result.
416432
417-
:return:
433+
:yields: iterable of :class:`.Record` objects
418434
"""
419435
hydrate = self.value_system.hydrate
420436
zipper = self.zipper
@@ -430,20 +446,33 @@ def records(self):
430446
yield zipper(keys, hydrate(values))
431447

432448
def summary(self):
433-
""" Return the summary, buffering any remaining records.
449+
""" Obtain the summary of this result, buffering any remaining records.
450+
451+
:returns: The :class:`.ResultSummary` for this result
434452
"""
435453
self.buffer()
436454
return self._summary
437455

438456
def consume(self):
439457
""" Consume the remainder of this result and return the summary.
458+
459+
.. NOTE:: It is generally recommended to use :meth:`.summary`
460+
instead of this method.
461+
462+
:returns: The :class:`.ResultSummary` for this result
440463
"""
441464
if self.online():
442465
list(self)
443466
return self.summary()
444467

445468
def single(self):
446-
""" Return the next record, failing if none or more than one remain.
469+
""" Obtain the next and only remaining record from this result.
470+
471+
A warning is generated if more than one record is available but
472+
the first of these is still returned.
473+
474+
:returns: the next :class:`.Record` or :const:`None` if none remain
475+
:warns: if more than one record is available
447476
"""
448477
records = list(self)
449478
size = len(records)
@@ -454,8 +483,10 @@ def single(self):
454483
return records[0]
455484

456485
def peek(self):
457-
""" Return the next record without advancing the cursor. Returns
458-
:const:`None` if no records remain.
486+
""" Obtain the next record from this result without consuming it.
487+
This leaves the record in the buffer for further processing.
488+
489+
:returns: the next :class:`.Record` or :const:`None` if none remain
459490
"""
460491
hydrate = self.value_system.hydrate
461492
zipper = self.zipper

0 commit comments

Comments
 (0)