🔍 Code Extractor

function get_dbo_establishment_with_references_usergroup_dbo_usergroup

Maturity: 42

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1801 - 1808
Complexity:
simple

Purpose

This function is designed to traverse a Neo4j graph database to find user groups associated with a particular establishment. It's useful for applications that need to identify which user groups have references to or are linked with a specific establishment entity, such as in organizational management systems, access control systems, or multi-tenant applications where establishments need to track their associated user groups.

Source Code

def get_dbo_establishment_with_references_usergroup_dbo_usergroup(source_id, limit=100):
    """Get dbo_UserGroup nodes connected to a dbo_Establishment via REFERENCES_USERGROUP"""
    query = """
    MATCH (source:dbo_Establishment {id: $source_id})-[r:REFERENCES_USERGROUP]->(target:dbo_UserGroup)
    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_Establishment node from which to start the traversal. This should be a string or integer value that matches the 'id' property of an existing Establishment node in the Neo4j database.

limit: Maximum number of dbo_UserGroup nodes to return from the query. Defaults to 100. This parameter helps control query performance and result set size. Must be a positive integer.

Return Value

Returns the result of the run_query function, which typically contains a list or collection of dbo_UserGroup 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 target dbo_UserGroup nodes. If no matching nodes are found, it returns an empty collection.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Get user groups for establishment with id '12345'
result = get_dbo_establishment_with_references_usergroup_dbo_usergroup('12345')
for record in result:
    user_group = record['target']
    print(f"User Group ID: {user_group['id']}")

# Example 2: Limit results to 10 user groups
result = get_dbo_establishment_with_references_usergroup_dbo_usergroup('12345', limit=10)

# Example 3: Process all returned user groups
user_groups = get_dbo_establishment_with_references_usergroup_dbo_usergroup('establishment_001', limit=50)
for record in user_groups:
    group = record['target']
    # Process each user group as needed

Best Practices

  • Ensure the source_id parameter matches the exact format and type of the 'id' property in your Neo4j database
  • Use appropriate limit values to prevent performance issues with large datasets
  • Handle cases where no matching nodes are found (empty result set)
  • Consider adding error handling around the function call to catch database connection issues
  • Verify that the run_query function properly manages Neo4j sessions and transactions
  • Index the 'id' property on dbo_Establishment nodes for better query performance
  • Consider pagination for large result sets instead of relying solely on the limit parameter
  • Validate that the REFERENCES_USERGROUP relationship exists in your database schema before querying

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_references_usergroup_relationship 83.6% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_houses_with_references_establishment_dbo_establishment 82.4% 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 80.5% 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 get_dbo_tnv_with_references_establishment_dbo_establishment 78.6% 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_flocks_with_references_establishment_dbo_establishment 77.9% similar

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

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