function get_dbo_tnv_with_references_establishment_dbo_establishment
Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific dbo_TNV node through a REFERENCES_ESTABLISHMENT relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
2089 - 2096
simple
Purpose
This function is designed to traverse a Neo4j graph database to find establishment entities referenced by a TNV (likely a business or organizational entity). It's useful for discovering relationships between TNV records and their associated establishments, with configurable result limits for performance management. The function executes a Cypher query and returns the matching establishment nodes.
Source Code
def get_dbo_tnv_with_references_establishment_dbo_establishment(source_id, limit=100):
"""Get dbo_Establishment nodes connected to a dbo_TNV via REFERENCES_ESTABLISHMENT"""
query = """
MATCH (source:dbo_TNV {id: $source_id})-[r:REFERENCES_ESTABLISHMENT]->(target:dbo_Establishment)
RETURN target
LIMIT $limit
"""
return run_query(query, {"source_id": source_id, "limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
source_id |
- | - | positional_or_keyword |
limit |
- | 100 | positional_or_keyword |
Parameter Details
source_id: The unique identifier of the source dbo_TNV node from which to find connected establishments. This should be a string or value that matches the 'id' property of a dbo_TNV node in the Neo4j database.
limit: Maximum number of dbo_Establishment nodes to return. Defaults to 100. This parameter helps control query performance and result set size. Should be a positive integer.
Return Value
Returns the result of the run_query function execution, which typically contains a list or collection of dbo_Establishment nodes that match the query criteria. The exact return type depends on the run_query implementation, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of the matched establishment nodes. Returns an empty collection if no matching establishments are found.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
from neo4j import GraphDatabase
# Get establishments referenced by a specific TNV
tnv_id = "TNV_12345"
establishments = get_dbo_tnv_with_references_establishment_dbo_establishment(tnv_id)
# Get only the first 10 establishments
establishments_limited = get_dbo_tnv_with_references_establishment_dbo_establishment(tnv_id, limit=10)
# Process results
for record in establishments:
establishment = record['target']
print(f"Establishment ID: {establishment.get('id')}")
Best Practices
- Always validate that source_id exists before calling this function to avoid unnecessary database queries
- Use appropriate limit values based on expected result sizes to optimize query performance
- Ensure the run_query function properly handles database connection errors and query failures
- Consider adding error handling around this function call to manage cases where the TNV node doesn't exist
- Be aware that this function depends on the run_query helper function being properly implemented with Neo4j connection management
- Consider adding pagination for large result sets instead of relying solely on the limit parameter
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 85.4% similar
-
function create_references_establishment_relationship_v3 84.9% similar
-
function get_dbo_houses_with_references_establishment_dbo_establishment 84.8% similar
-
function get_dbo_treatments_with_references_establishment_dbo_establishment 84.7% similar
-
function get_dbo_flocks_with_references_establishment_dbo_establishment 81.2% similar