def create_node_if_not_exists( self, node: GraphNode, properties: Set[AnyStr] ): # TODO: define properties on the node entity itself? properties = properties.union(self.ADDITIONAL_NODE_PROPERTIES) query_params = self._get_properties_for_query(node, properties) create_query = CypherQuery( f"MERGE (n:{node.label_string} {query_params.query_string} )") result = self._client.add_to_batch(create_query, query_params)
def nuke_dataset(self): deleted = 1 while deleted > 0: query = CypherQuery(""" MATCH (n:NODE {dataset_name: $dataset_name}) WITH n LIMIT 100000 DETACH DELETE n RETURN count(*) as c; """) result = self._client.execute_cypher_write( query, QueryParams(dataset_name=self.dataset_name)) deleted = list(result)[0]["c"] print(f"Deleted {deleted} rows")
def create_edge_if_not_exists(self, edge: GraphEdge, properties: Set[AnyStr]): _from = edge._from _to = edge._to query_params = self._get_properties_for_query(edge, properties) match = f"MATCH (from:{_from.label_string} {{ id: $from_id }}), (to:{_to.label_string} {{ id: $to_id }})" merge = f"MERGE (from)-[r:{edge.relationship} {query_params.query_string} ]->(to)" create_query = CypherQuery(match + "\n" + merge) query_params = query_params.union( QueryParams(from_id=str(_from.id.value), to_id=str(_to.id.value))) result = self._client.add_to_batch(create_query, query_params)
def create_indexes(): client.execute_cypher_write(CypherQuery("CREATE INDEX ON :NODE(id)"), QueryParams()) #client.execute_cypher_write(CypherQuery("CREATE INDEX ON :NODE(id, dataset_name)"), QueryParams()) pass
def nuke_dataset(self): query = CypherQuery( "MATCH (n:NODE {dataset_name: $dataset_name}) DETACH DELETE n") self._client.execute_cypher_write( query, QueryParams(dataset_name=self.dataset_name))