def run(self, cypher, parameters=None, **kwparameters): """ Send a Cypher query to the server for execution and return a :py:class:`.Cursor` for navigating its result. :param cypher: Cypher query :param parameters: dictionary of parameters :returns: :py:class:`.Cursor` object """ from py2neo.client import Connection self._assert_unfinished("Cannot run query in finished transaction") try: entities = self._entities.popleft() except IndexError: entities = {} try: hydrant = Connection.default_hydrant(self._connector.profile, self.graph) parameters = dict(parameters or {}, **kwparameters) if self._transaction: result = self._connector.run_in_tx(self._transaction, cypher, parameters, hydrant=hydrant) else: result = self._connector.auto_run(self.graph.name, cypher, parameters, readonly=self.readonly, hydrant=hydrant) return Cursor(result, hydrant, entities) finally: if not self._transaction: self.finish()
def run(self, cypher, parameters=None, **kwparameters): """ Send a Cypher query to the server for execution and return a :py:class:`~.cypher.Cursor` for navigating its result. :param cypher: Cypher query :param parameters: dictionary of parameters :returns: :py:class:`~.cypher.Cursor` object """ from py2neo.client import Connection if self.closed: raise TypeError("Cannot run query in closed transaction") try: hydrant = Connection.default_hydrant(self._connector.profile, self.graph) parameters = dict(parameters or {}, **kwparameters) if self.ref: result = self._connector.run(self.ref, cypher, parameters) else: result = self._connector.auto_run(cypher, parameters, graph_name=self.graph.name, readonly=self.readonly) return Cursor(result, hydrant) finally: if not self.ref: self._closed = True
def _poll_connection(self, port_name, timeout=0): """ Repeatedly attempt to open a connection to a Bolt server. """ t0 = monotonic() profile = self.profiles[port_name] log.debug("Trying to open connection to %s", profile) errors = set() again = True wait = 0.1 while again: try: cx = Connection.open(profile) except InvalidVersion as e: log.info( "Encountered invalid Neo4j version '%s'. Continuing anyway (this is a dev tool)", e) return None except ConnectionUnavailable as e: errors.add(" ".join(map(str, e.args))) else: if cx: return cx again = monotonic() - t0 < (timeout or 0) if again: sleep(wait) wait *= 2 log.error("Could not open connection to %s (%r)", profile, errors) raise ConnectionUnavailable("Could not open connection")
def __init__(self, profile=None, **settings): profile = _ConnectionProfile(profile, **settings) try: self._cx = _Connection.open(profile) except _ConnectionUnavailable as error: raise_from(self.OperationalError("Connection unavailable"), error) self._tx = None self._db = None
def connection(connection_profile): cx = Connection.open(connection_profile) yield cx cx.close()
def connection(service_profile): cx = Connection.open(service_profile) yield cx cx.close()