3737)
3838from neo4j ._exceptions import BoltIncompleteCommitError
3939from neo4j .work import Workspace , WorkspaceConfig
40- from neo4j .work .summary import BoltStatementResultSummary
40+ from neo4j .work .summary import ResultSummary
4141
4242
4343log = 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 :
0 commit comments