Skip to content

Commit 2a72d8c

Browse files
4.0 breaking change renaming (#362)
* renamed class BoltStatementResult to Result * renamed class BoltStatementResultSummary to ResultSummary * renamed statement argument to query * Renamed class Statement to Query * renamed in ResultSummary statement to query statement_type to query_type * changed the metadata argument statement to be query * renamed statement to query in class Transaction and Bolt * renamed statement and cypher to query in class Session
1 parent 841ca5e commit 2a72d8c

File tree

11 files changed

+84
-76
lines changed

11 files changed

+84
-76
lines changed

docs/source/results.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Consuming Results
33
*****************
44

5-
Every time Cypher is executed, a :class:`.BoltStatementResult` is returned.
5+
Every time Cypher is executed, a :class:`neo4j.Result` is returned.
66
This provides a handle to the result of the query, giving access to the records within it as well as the result metadata.
77

88
Each result consists of header metadata, zero or more :class:`.Record` objects and footer metadata (the summary).
99
Results also contain a buffer that automatically stores unconsumed records when results are consumed out of order.
10-
A :class:`.BoltStatementResult` is attached to an active connection, through a :class:`.Session`, until all its content has been buffered or consumed.
10+
A :class:`neo4j.Result` is attached to an active connection, through a :class:`.Session`, until all its content has been buffered or consumed.
1111

12-
.. class:: neo4j.BoltStatementResult
12+
.. class:: neo4j.Result
1313

1414
.. describe:: iter(result)
1515

@@ -103,7 +103,7 @@ A :class:`.BoltStatementResult` is attached to an active connection, through a :
103103
Summary Details
104104
---------------
105105

106-
.. autoclass:: neo4j.BoltStatementResultSummary
106+
.. autoclass:: neo4j.ResultSummary
107107
:members:
108108

109109
.. autoclass:: neo4j.SummaryCounters

docs/source/types/graph.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Path :class:`.Path`
2121
.. class:: neo4j.types.graph.Graph
2222

2323
A local, self-contained graph object that acts as a container for :class:`.Node` and :class:`.Relationship` instances.
24-
This is typically obtained via the :meth:`.BoltStatementResult.graph` method.
24+
This is typically obtained via the :meth:`neo4j.Result.graph` method.
2525

2626
.. autoattribute:: nodes
2727

neo4j/io/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ def __enter__(self):
215215
def __exit__(self, exc_type, exc_value, traceback):
216216
self.close()
217217

218-
def run(self, statement, parameters=None, mode=None, bookmarks=None, metadata=None,
218+
def run(self, query, parameters=None, mode=None, bookmarks=None, metadata=None,
219219
timeout=None, db=None, **handlers):
220220
""" Appends a RUN message to the output stream.
221221
222-
:param statement: Cypher query string
222+
:param query: Cypher query string
223223
:param parameters: dictionary of Cypher parameters
224224
:param mode: access mode for routing - "READ" or "WRITE" (default)
225225
:param bookmarks: iterable of bookmark values after which this transaction should begin

neo4j/io/_bolt3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def hello(self):
144144
self.send_all()
145145
self.fetch_all()
146146

147-
def run(self, statement, parameters=None, mode=None, bookmarks=None, metadata=None,
147+
def run(self, query, parameters=None, mode=None, bookmarks=None, metadata=None,
148148
timeout=None, db=None, **handlers):
149149
if db is not None:
150150
raise ValueError("Database selection is not supported in Bolt 3")
@@ -168,9 +168,9 @@ def run(self, statement, parameters=None, mode=None, bookmarks=None, metadata=No
168168
extra["tx_timeout"] = int(1000 * timeout)
169169
except TypeError:
170170
raise TypeError("Timeout must be specified as a number of seconds")
171-
fields = (statement, parameters, extra)
171+
fields = (query, parameters, extra)
172172
log.debug("[#%04X] C: RUN %s", self.local_port, " ".join(map(repr, fields)))
173-
if statement.upper() == u"COMMIT":
173+
if query.upper() == u"COMMIT":
174174
self._append(b"\x10", fields, CommitResponse(self, **handlers))
175175
else:
176176
self._append(b"\x10", fields, Response(self, **handlers))

neo4j/io/_bolt4x0.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def hello(self):
144144
self.send_all()
145145
self.fetch_all()
146146

147-
def run(self, statement, parameters=None, mode=None, bookmarks=None, metadata=None,
147+
def run(self, query, parameters=None, mode=None, bookmarks=None, metadata=None,
148148
timeout=None, db=None, **handlers):
149149
if not parameters:
150150
parameters = {}
@@ -168,9 +168,9 @@ def run(self, statement, parameters=None, mode=None, bookmarks=None, metadata=No
168168
extra["tx_timeout"] = int(1000 * timeout)
169169
except TypeError:
170170
raise TypeError("Timeout must be specified as a number of seconds")
171-
fields = (statement, parameters, extra)
171+
fields = (query, parameters, extra)
172172
log.debug("[#%04X] C: RUN %s", self.local_port, " ".join(map(repr, fields)))
173-
if statement.upper() == u"COMMIT":
173+
if query.upper() == u"COMMIT":
174174
self._append(b"\x10", fields, CommitResponse(self, **handlers))
175175
else:
176176
self._append(b"\x10", fields, Response(self, **handlers))

neo4j/work/simple.py

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838
from neo4j._exceptions import BoltIncompleteCommitError
3939
from neo4j.work import Workspace, WorkspaceConfig
40-
from neo4j.work.summary import BoltStatementResultSummary
40+
from neo4j.work.summary import ResultSummary
4141

4242

4343
log = getLogger("neo4j")
@@ -128,33 +128,33 @@ def close(self):
128128
finally:
129129
self._disconnect()
130130

131-
def run(self, cypher, parameters=None, **kwparameters):
132-
""" Run a Cypher statement within an auto-commit transaction.
131+
def run(self, query, parameters=None, **kwparameters):
132+
""" Run a Cypher query within an auto-commit transaction.
133133
134-
The statement is sent and the result header received
135-
immediately but the :class:`.StatementResult` content is
134+
The query is sent and the result header received
135+
immediately but the :class:`neo4j.Result` content is
136136
fetched lazily as consumed by the client application.
137137
138-
If a statement is executed before a previous
139-
:class:`.StatementResult` in the same :class:`.Session` has
138+
If a query is executed before a previous
139+
:class:`neo4j.Result` in the same :class:`.Session` has
140140
been fully consumed, the first result will be fully fetched
141141
and buffered. Note therefore that the generally recommended
142142
pattern of usage is to fully consume one result before
143-
executing a subsequent statement. If two results need to be
143+
executing a subsequent query. If two results need to be
144144
consumed in parallel, multiple :class:`.Session` objects
145145
can be used as an alternative to result buffering.
146146
147147
For more usage details, see :meth:`.Transaction.run`.
148148
149-
:param cypher: Cypher statement
149+
:param query: Cypher query
150150
:param parameters: dictionary of parameters
151151
:param kwparameters: additional keyword parameters
152-
:returns: :class:`.StatementResult` object
152+
:returns: :class:`neo4j.Result` object
153153
"""
154-
if not cypher:
155-
raise ValueError("Cannot run an empty statement")
156-
if not isinstance(cypher, (str, Statement)):
157-
raise TypeError("Statement must be a string or a Statement instance")
154+
if not query:
155+
raise ValueError("Cannot run an empty query")
156+
if not isinstance(query, (str, Query)):
157+
raise TypeError("query must be a string or a Query instance")
158158

159159
if not self._connection:
160160
self._connect(self._config.default_access_mode)
@@ -164,24 +164,24 @@ def run(self, cypher, parameters=None, **kwparameters):
164164

165165
has_transaction = self.has_transaction()
166166

167-
statement_text = str(cypher)
168-
statement_metadata = getattr(cypher, "metadata", None)
169-
statement_timeout = getattr(cypher, "timeout", None)
167+
query_text = str(query)
168+
query_metadata = getattr(query, "metadata", None)
169+
query_timeout = getattr(query, "timeout", None)
170170
parameters = DataDehydrator.fix_parameters(dict(parameters or {}, **kwparameters))
171171

172172
def fail(_):
173173
self._close_transaction()
174174

175175
hydrant = DataHydrator()
176176
result_metadata = {
177-
"statement": statement_text,
177+
"query": query_text,
178178
"parameters": parameters,
179179
"server": server,
180180
"protocol_version": protocol_version,
181181
}
182182
run_metadata = {
183-
"metadata": statement_metadata,
184-
"timeout": statement_timeout,
183+
"metadata": query_metadata,
184+
"timeout": query_timeout,
185185
"on_success": result_metadata.update,
186186
"on_failure": fail,
187187
}
@@ -193,20 +193,20 @@ def done(summary_metadata):
193193
self._bookmarks_in = tuple([bookmark])
194194
self._bookmark_out = bookmark
195195

196-
self._last_result = result = BoltStatementResult(self, hydrant, result_metadata)
196+
self._last_result = result = Result(self, hydrant, result_metadata)
197197

198198
if has_transaction:
199-
if statement_metadata:
199+
if query_metadata:
200200
raise ValueError("Metadata can only be attached at transaction level")
201-
if statement_timeout:
201+
if query_timeout:
202202
raise ValueError("Timeouts only apply at transaction level")
203203
# TODO: fail if explicit database name has been set
204204
else:
205205
run_metadata["bookmarks"] = self._bookmarks_in
206206

207207
# TODO: capture ValueError and surface as SessionError/TransactionError if
208208
# TODO: explicit database selection has been made
209-
cx.run(statement_text, parameters, **run_metadata)
209+
cx.run(query_text, parameters, **run_metadata)
210210
cx.pull(
211211
on_records=lambda records: result._records.extend(
212212
hydrant.hydrate_records(result.keys(), records)),
@@ -488,40 +488,40 @@ def __exit__(self, exc_type, exc_value, traceback):
488488
self._success = not bool(exc_type)
489489
self._close()
490490

491-
def run(self, statement, parameters=None, **kwparameters):
492-
""" Run a Cypher statement within the context of this transaction.
491+
def run(self, query, parameters=None, **kwparameters):
492+
""" Run a Cypher query within the context of this transaction.
493493
494-
The statement is sent to the server lazily, when its result is
495-
consumed. To force the statement to be sent to the server, use
494+
The query is sent to the server lazily, when its result is
495+
consumed. To force the query to be sent to the server, use
496496
the :meth:`.Transaction.sync` method.
497497
498-
Cypher is typically expressed as a statement template plus a
498+
Cypher is typically expressed as a query template plus a
499499
set of named parameters. In Python, parameters may be expressed
500500
through a dictionary of parameters, through individual parameter
501501
arguments, or as a mixture of both. For example, the `run`
502-
statements below are all equivalent::
502+
queries below are all equivalent::
503503
504-
>>> statement = "CREATE (a:Person {name:{name}, age:{age}})"
505-
>>> tx.run(statement, {"name": "Alice", "age": 33})
506-
>>> tx.run(statement, {"name": "Alice"}, age=33)
507-
>>> tx.run(statement, name="Alice", age=33)
504+
>>> query = "CREATE (a:Person {name:{name}, age:{age}})"
505+
>>> tx.run(query, {"name": "Alice", "age": 33})
506+
>>> tx.run(query, {"name": "Alice"}, age=33)
507+
>>> tx.run(query, name="Alice", age=33)
508508
509509
Parameter values can be of any type supported by the Neo4j type
510510
system. In Python, this includes :class:`bool`, :class:`int`,
511511
:class:`str`, :class:`list` and :class:`dict`. Note however that
512512
:class:`list` properties must be homogenous.
513513
514-
:param statement: template Cypher statement
514+
:param query: template Cypher query
515515
:param parameters: dictionary of parameters
516516
:param kwparameters: additional keyword parameters
517-
:returns: :class:`.StatementResult` object
517+
:returns: :class:`neo4j.Result` object
518518
:raise TransactionError: if the transaction is closed
519519
"""
520520
self._assert_open()
521-
return self.session.run(statement, parameters, **kwparameters)
521+
return self.session.run(query, parameters, **kwparameters)
522522

523523
def sync(self):
524-
""" Force any queued statements to be sent to the server and
524+
""" Force any queued queries to be sent to the server and
525525
all related results to be fetched and buffered.
526526
527527
:raise TransactionError: if the transaction is closed
@@ -578,8 +578,13 @@ def _assert_open(self):
578578
raise TransactionError("Transaction closed")
579579

580580

581-
class Statement:
581+
class Query:
582+
""" Create a new query.
582583
584+
:param text: The query text.
585+
:param metadata: Dictionary of parameters, metadata attached to the query.
586+
:param timeout: Timeout in seconds.
587+
"""
583588
def __init__(self, text, metadata=None, timeout=None):
584589
self.text = text
585590
try:
@@ -595,8 +600,8 @@ def __str__(self):
595600
return str(self.text)
596601

597602

598-
class BoltStatementResult:
599-
""" A handler for the result of Cypher statement execution. Instances
603+
class Result:
604+
""" A handler for the result of Cypher query execution. Instances
600605
of this class are typically constructed and returned by
601606
:meth:`.Session.run` and :meth:`.Transaction.run`.
602607
"""
@@ -668,17 +673,17 @@ def records(self):
668673
def summary(self):
669674
""" Obtain the summary of this result, buffering any remaining records.
670675
671-
:returns: The :class:`.ResultSummary` for this result
676+
:returns: The :class:`neo4j.ResultSummary` for this result
672677
"""
673678
self.detach()
674679
if self._summary is None:
675-
self._summary = BoltStatementResultSummary(**self._metadata)
680+
self._summary = ResultSummary(**self._metadata)
676681
return self._summary
677682

678683
def consume(self):
679684
""" Consume the remainder of this result and return the summary.
680685
681-
:returns: The :class:`.ResultSummary` for this result
686+
:returns: The :class:`neo4j.ResultSummary` for this result
682687
"""
683688
if self.attached():
684689
for _ in self:

neo4j/work/summary.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
BOLT_VERSION_4 = 4
2828

2929

30-
class BoltStatementResultSummary:
31-
""" A summary of execution returned with a :class:`.StatementResult` object.
30+
class ResultSummary:
31+
""" A summary of execution returned with a :class:`.Result` object.
3232
"""
3333

3434
#: The version of Bolt protocol over which this result was obtained.
@@ -37,14 +37,14 @@ class BoltStatementResultSummary:
3737
#: The server on which this result was generated.
3838
server = None
3939

40-
#: The statement that was executed to produce this result.
41-
statement = None
40+
#: The query that was executed to produce this result.
41+
query = None
4242

4343
#: Dictionary of parameters passed with the statement.
4444
parameters = None
4545

46-
#: The type of statement (``'r'`` = read-only, ``'rw'`` = read/write).
47-
statement_type = None
46+
#: The type of query (``'r'`` = read-only, ``'rw'`` = read/write).
47+
query_type = None
4848

4949
#: A set of statistical information held in a :class:`.Counters` instance.
5050
counters = None
@@ -71,9 +71,9 @@ def __init__(self, **metadata):
7171
self.metadata = metadata
7272
self.protocol_version = metadata.get("protocol_version")
7373
self.server = metadata.get("server")
74-
self.statement = metadata.get("statement")
74+
self.query = metadata.get("query")
7575
self.parameters = metadata.get("parameters")
76-
self.statement_type = metadata.get("type")
76+
self.query_type = metadata.get("type")
7777
self.counters = SummaryCounters(metadata.get("stats", {}))
7878
if self.protocol_version[0] < BOLT_VERSION_3:
7979
self.result_available_after = metadata.get("result_available_after")

tests/integration/examples/test_autocommit_transaction_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
# tag::autocommit-transaction-import[]
23-
from neo4j.work.simple import Statement
23+
from neo4j.work.simple import Query
2424
# end::autocommit-transaction-import[]
2525

2626

@@ -39,7 +39,7 @@ def add_person(self, name):
3939
# Alternative implementation, with a one second timeout
4040
def add_person_within_a_second(self, name):
4141
with self.driver.session() as session:
42-
session.run(Statement("CREATE (a:Person {name: $name})", timeout=1.0), name=name)
42+
session.run(Query("CREATE (a:Person {name: $name})", timeout=1.0), name=name)
4343
# end::autocommit-transaction[]
4444

4545

0 commit comments

Comments
 (0)