def query_node(node_type=None, variable=None, **properties): results = [] variable = str(variable) if variable is not None else "n" cypher_command = "{match} RETURN {variable}".format( match=NodeCommands.match_command_for_type(variable=variable, node_type=node_type, **properties), variable=variable) cypher_results = CypherOperations._execute( [Operation(OperationType.RETRIEVE, command=cypher_command)]) results_data = [ row for sub_results in [result.data() for result in cypher_results] for row in sub_results ] if len(results_data) == 0: return results for data in results_data: result_value = data[variable] if type(result_value) != Neo4jNode: continue # maybe raise exception here node_properties = { Node.get_properties_mapping()[k]: v for k, v in expand(result_value).items() } results.append(Node(**node_properties)) return results
def node_exist(node, variable=None): variable = str(variable) if variable is not None else "n" cypher_command = "{match} RETURN {variable}".format( match=NodeCommands(node).match_command(variable=variable, node_type=node.node_type), variable=variable) results = CypherOperations._execute( [Operation(OperationType.RETRIEVE, command=cypher_command)]) results_data = [ row for sub_results in [result.data() for result in results] for row in sub_results ] if len(results_data) == 0: return None result_value = results_data[0][variable] if type(result_value) != Neo4jNode: return None # maybe raise exception here node_properties = { Node.get_properties_mapping()[k]: v for k, v in expand(result_value).items() } node_properties["node_type"] = node.node_type return Node(**node_properties) == node