🔍 Code Extractor

function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment

Maturity: 42

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1833 - 1840
Complexity:
simple

Purpose

This function is designed to traverse a graph database relationship between establishment cycles and establishments. It's useful for finding all establishment entities associated with a particular establishment cycle, such as retrieving all physical locations or business entities linked to a specific operational cycle or time period. The function supports pagination through a limit parameter.

Source Code

def get_dbo_establishmentcycles_with_references_establishment_dbo_establishment(source_id, limit=100):
    """Get dbo_Establishment nodes connected to a dbo_EstablishmentCycles via REFERENCES_ESTABLISHMENT"""
    query = """
    MATCH (source:dbo_EstablishmentCycles {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 (id property) of the dbo_EstablishmentCycles node from which to start the traversal. This should be a string or value that matches the 'id' property in the Neo4j database for the source node.

limit: Maximum number of dbo_Establishment nodes to return. Defaults to 100. This parameter controls pagination and prevents returning excessively large result sets. Must be a positive integer.

Return Value

Returns the result of run_query() function, which typically contains a list or collection of dbo_Establishment nodes that match the query criteria. The exact return type depends on the implementation of run_query(), but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of each target dbo_Establishment node. Returns an empty collection if no matching relationships 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

# Example: Get establishments for a specific cycle
cycle_id = "cycle_2024_Q1"
establishments = get_dbo_establishmentcycles_with_references_establishment_dbo_establishment(cycle_id, limit=50)

# Process results
for record in establishments:
    establishment = record['target']
    print(f"Establishment ID: {establishment['id']}")

# Get all establishments (up to 100) for another cycle
all_establishments = get_dbo_establishmentcycles_with_references_establishment_dbo_establishment("cycle_2024_Q2")

Best Practices

  • Ensure the source_id exists in the database before calling to avoid empty results
  • Use appropriate limit values to balance between performance and completeness of results
  • The run_query() function must be properly implemented with error handling and connection management
  • Consider implementing connection pooling for the Neo4j driver if making multiple queries
  • Validate that the source_id parameter is properly sanitized, though parameterized queries provide protection against injection
  • Handle cases where no relationships exist gracefully in calling code
  • Consider adding error handling for database connection failures
  • For large datasets, implement pagination by calling the function multiple times with different offsets if needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_houses_with_references_establishment_dbo_establishment 87.6% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_establishmentcycles 86.5% similar

    Retrieves all nodes of type dbo_EstablishmentCycles from a Neo4j graph database with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishmentcycles_by_id 86.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_dbo_tnv_with_references_establishment_dbo_establishment 85.4% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_treatments_with_references_establishment_dbo_establishment 84.4% similar

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

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