🔍 Code Extractor

function get_reference_municipalities_by_uid

Maturity: 39

Retrieves a single Reference_Municipalities node from a Neo4j graph database by matching its unique identifier (UID).

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
625 - 632
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific municipality reference record using its UID. It's designed for retrieving individual municipality data from a graph database, typically used in applications that need to look up municipality information by a unique identifier. The function returns the first matching node or None if no match is found.

Source Code

def get_reference_municipalities_by_uid(uid):
    """Get a Reference_Municipalities node by its UID"""
    query = """
    MATCH (n:Reference_Municipalities {UID: $uid})
    RETURN n
    """
    result = run_query(query, {"uid": uid})
    return result[0] if result else None

Parameters

Name Type Default Kind
uid - - positional_or_keyword

Parameter Details

uid: The unique identifier (UID) of the Reference_Municipalities node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be a valid, existing UID for a municipality reference record.

Return Value

Returns a single Reference_Municipalities node object (typically a dictionary or Neo4j node object) if a matching UID is found, or None if no matching node exists in the database. The returned node contains all properties associated with that municipality reference record.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j is configured
from neo4j import GraphDatabase

# Example usage
uid_to_search = "MUN-12345"
municipality = get_reference_municipalities_by_uid(uid_to_search)

if municipality:
    print(f"Found municipality: {municipality}")
else:
    print("Municipality not found")

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Validate the uid parameter before passing it to prevent injection attacks or invalid queries
  • Consider adding error handling for database connection failures
  • The function assumes run_query returns a list; ensure this contract is maintained
  • Consider adding logging for debugging purposes when nodes are not found
  • Ensure proper Neo4j database indexes exist on the UID property for optimal query performance
  • Handle potential None return value appropriately in calling code

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_reference_municipalities_by_id 91.9% similar

    Retrieves a single Reference_Municipalities node from a Neo4j graph database by matching its unique ID property.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_reference_municipalities 81.5% similar

    Queries a Neo4j graph database to retrieve Reference_Municipalities nodes with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_reference_municipalities 71.7% similar

    Creates a new Reference_Municipalities node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishment_with_references_municipalities_reference_municipalities 70.4% similar

    Retrieves Reference_Municipalities nodes from a Neo4j graph database that are connected to a specific dbo_Establishment node via a REFERENCES_MUNICIPALITIES relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_parameter_medicationtypes_by_uid 68.1% similar

    Retrieves a single Parameter_MedicationTypes node from a Neo4j graph database by matching its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse