latest
This commit is contained in:
@@ -15,16 +15,16 @@ logging = logger.get_logger(
|
||||
import modules.database.tools.queries as query
|
||||
from contextlib import suppress
|
||||
|
||||
def get_node_by_unique_id_and_adjacent_nodes(session, unique_id):
|
||||
return session.read_transaction(_get_node_by_unique_id_and_adjacent_nodes, unique_id)
|
||||
def get_node_by_uuid_string_and_adjacent_nodes(session, uuid_string):
|
||||
return session.read_transaction(_get_node_by_uuid_string_and_adjacent_nodes, uuid_string)
|
||||
|
||||
def _get_node_by_unique_id_and_adjacent_nodes(tx, unique_id):
|
||||
def _get_node_by_uuid_string_and_adjacent_nodes(tx, uuid_string):
|
||||
query = """
|
||||
MATCH (n {unique_id: $unique_id})
|
||||
MATCH (n {uuid_string: $uuid_string})
|
||||
OPTIONAL MATCH (n)-[r]-(adjacent)
|
||||
RETURN n AS node, COLLECT(DISTINCT {node: adjacent, relationship: r}) AS connected_nodes
|
||||
"""
|
||||
result = tx.run(query, unique_id=unique_id)
|
||||
result = tx.run(query, uuid_string=uuid_string)
|
||||
record = result.single()
|
||||
if record:
|
||||
node = record["node"]
|
||||
@@ -242,20 +242,20 @@ def _find_nodes_by_label(tx, label):
|
||||
result = tx.run(query)
|
||||
return [record["n"] for record in result]
|
||||
|
||||
def get_node_by_unique_id(session, unique_id):
|
||||
return session.read_transaction(_get_node_by_unique_id, unique_id)
|
||||
def get_node_by_uuid_string(session, uuid_string):
|
||||
return session.read_transaction(_get_node_by_uuid_string, uuid_string)
|
||||
|
||||
def _get_node_by_unique_id(tx, unique_id):
|
||||
def _get_node_by_uuid_string(tx, uuid_string):
|
||||
query = f"""
|
||||
MATCH (n)
|
||||
WHERE n.unique_id = $unique_id
|
||||
WHERE n.uuid_string = $uuid_string
|
||||
RETURN n
|
||||
"""
|
||||
logging.debug(f"Executing query with unique_id: {unique_id}")
|
||||
result = tx.run(query, unique_id=unique_id)
|
||||
logging.debug(f"Executing query with uuid_string: {uuid_string}")
|
||||
result = tx.run(query, uuid_string=uuid_string)
|
||||
record = result.single()
|
||||
if record is None:
|
||||
logging.warning(f"No node found with unique_id: {unique_id}")
|
||||
logging.warning(f"No node found with uuid_string: {uuid_string}")
|
||||
return None
|
||||
return record[0]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user