示例#1
0
def test_keys(connector):
    result = connector.auto_run("RETURN 'Alice' AS name, 33 AS age")
    connector.pull(result, -1)
    cursor = Cursor(result)
    expected = ["name", "age"]
    actual = cursor.keys()
    assert expected == actual
示例#2
0
def test_records(connector):
    cursor = Cursor(
        connector.auto_run("UNWIND range(1, $x) AS n RETURN n, n * n AS n_sq", {"x": 3}))
    expected = deque([(1, 1), (2, 4), (3, 9)])
    for actual_record in cursor:
        expected_record = Record(["n", "n_sq"], expected.popleft())
        assert expected_record == actual_record
示例#3
0
    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
示例#4
0
def test_stats(connector):
    cursor = Cursor(connector.auto_run("CREATE ()"))
    stats = cursor.stats()
    assert stats["nodes_created"] == 1
示例#5
0
def test_keys(connector):
    cursor = Cursor(connector.auto_run("RETURN 'Alice' AS name, 33 AS age"))
    expected = ["name", "age"]
    actual = cursor.keys()
    assert expected == actual
示例#6
0
def test_stats(connector):
    result = connector.auto_run("CREATE ()")
    connector.pull(result, -1)
    cursor = Cursor(result)
    stats = cursor.stats()
    assert stats["nodes_created"] == 1