def test_can_execute(graph): query = CypherQuery(graph, "CREATE (a {name:'Alice'}) " "RETURN a.name") results = query.execute() assert len(results) == 1 assert len(results[0]) == 1 assert results[0][0] == "Alice"
def save(self, subj, node=None): """ Save an object to a database node. :param subj: the object to save :param node: the database node to save to (if omitted, will re-save to same node as previous save) """ if node is not None: subj.__node__ = node # naively copy properties from object to node props = {} for key, value in subj.__dict__.items(): if not key.startswith("_"): props[key] = value if hasattr(subj, "__node__"): subj.__node__.set_properties(props) query = CypherQuery(self.graph, "START a=node({A}) " "MATCH (a)-[r]->(b) " "DELETE r") query.execute(A=subj.__node__._id) else: subj.__node__, = self.graph.create(props) # write rels if hasattr(subj, "__rel__"): batch = WriteBatch(self.graph) for rel_type, rels in subj.__rel__.items(): for rel_props, endpoint in rels: end_node = self._get_node(endpoint) if end_node not in self.graph: raise ValueError(end_node) batch.create((subj.__node__, rel_type, end_node, rel_props)) batch.run() return subj
def pull(self): query = CypherQuery(self.graph, "START a=node({a}) RETURN a") results = query.execute(a=self._id) node, = results[0].values super(Node, self).properties.clear() super(Node, self).properties.update(node.properties) self._Node__stale.clear()
def test_can_stream(graph): query = CypherQuery(graph, "CREATE (a {name:'Alice'}) " "RETURN a.name") stream = query.stream() results = list(stream) assert len(results) == 1 assert len(results[0]) == 1 assert results[0][0] == "Alice"
def test_can_execute_one(graph): query = CypherQuery(graph, "CREATE (a {name:'Alice'}) " "RETURN a.name") result = query.execute_one() assert result == "Alice"
def test_can_run(graph): query = CypherQuery(graph, "CREATE (a {name:'Alice'}) " "RETURN a.name") query.run() assert True