🔍 Code Extractor

function get_dbo_flocks_with_references_establishment_dbo_establishment

Maturity: 40

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1865 - 1872
Complexity:
simple

Purpose

This function is designed to traverse a graph database relationship between Flocks and Establishment entities. It's useful for finding all establishments referenced by a particular flock, with configurable result limits. The function executes a Cypher query to perform pattern matching in Neo4j and returns the connected establishment nodes.

Source Code

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

limit: Maximum number of dbo_Establishment nodes to return. Defaults to 100. This parameter controls query performance and result set size. Should be a positive integer.

Return Value

Returns the result of the 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 the matched establishment nodes. 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
# 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['target'] for record in result]

# Use the function
flock_id = 'flock_12345'
establishments = get_dbo_flocks_with_references_establishment_dbo_establishment(flock_id, limit=50)

# Process results
for establishment in establishments:
    print(f"Establishment: {establishment}")

# Clean up
driver.close()

Best Practices

  • Ensure the run_query function is properly implemented with error handling and connection management
  • Use appropriate limit values to prevent performance issues with large datasets
  • Validate that source_id exists before calling this function to avoid unnecessary database queries
  • Consider implementing connection pooling for the Neo4j driver in production environments
  • Add error handling around the function call to manage cases where the source_id doesn't exist or the database is unavailable
  • Close the Neo4j driver connection properly when done with all queries
  • Consider adding indexes on the 'id' property of dbo_Flocks nodes for better query performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_establishment_with_references_flocktypes_dbo_flocktypes 90.6% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_houses_with_references_establishment_dbo_establishment 83.5% 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_dbo_establishmentcycles_with_references_establishment_dbo_establishment 83.1% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_establishment_relationship_v5 82.8% similar

    Creates a REFERENCES_ESTABLISHMENT relationship in a Neo4j graph database between a dbo_Flocks node (source) and a dbo_Establishment node (target), with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_tnv_with_references_establishment_dbo_establishment 81.2% 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
← Back to Browse