🔍 Code Extractor

function get_dbo_establishment_by_uid

Maturity: 39

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
742 - 749
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific establishment node labeled as 'dbo_Establishment' using its UID property. It's designed for retrieving individual establishment records from a knowledge graph, returning the first matching node or None if no match is found. This is useful in applications that need to look up establishment details by a unique identifier.

Source Code

def get_dbo_establishment_by_uid(uid):
    """Get a dbo_Establishment node by its UID"""
    query = """
    MATCH (n:dbo_Establishment {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 dbo_Establishment node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should correspond to a unique establishment identifier in your data model.

Return Value

Returns a dictionary-like object representing the matched dbo_Establishment node if found, containing all properties of that node. Returns None if no node with the specified UID exists. The exact structure depends on the properties stored in the dbo_Establishment nodes in your Neo4j database.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
from neo4j import GraphDatabase

driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))

def run_query(query, params):
    with driver.session() as session:
        result = session.run(query, params)
        return [record['n'] for record in result]

# Using the function
uid_to_find = 'EST12345'
establishment = get_dbo_establishment_by_uid(uid_to_find)

if establishment:
    print(f"Found establishment: {establishment}")
else:
    print(f"No establishment found with UID: {uid_to_find}")

Best Practices

  • Ensure the run_query function is properly implemented with error handling for database connection issues
  • Validate the uid parameter before passing it to prevent injection attacks or invalid queries
  • Consider adding error handling for database connection failures or query execution errors
  • The function assumes run_query returns a list; ensure this contract is maintained
  • Close Neo4j driver connections properly when the application terminates
  • Consider adding logging for debugging purposes when nodes are not found
  • Ensure the UID property is indexed in Neo4j for optimal query performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_establishment_by_id 89.1% similar

    Retrieves a single dbo_Establishment node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishmentcycles_by_uid 89.0% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishmentcycles_by_id 78.2% similar

    Retrieves a single dbo_EstablishmentCycles node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_establishment 77.1% similar

    Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_Establishment' with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishment_with_references_usergroup_dbo_usergroup 75.0% similar

    Queries a Neo4j graph database to retrieve dbo_UserGroup nodes that are connected to a specific dbo_Establishment node through a REFERENCES_USERGROUP relationship.

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