🔍 Code Extractor

function get_dbo_usergroup_by_uid

Maturity: 41

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1171 - 1178
Complexity:
simple

Purpose

This function queries a Neo4j database to fetch a specific user group node identified by its UID property. It's designed for retrieving individual user group records from a graph database, typically used in applications that manage user permissions, access control, or organizational structures stored in Neo4j. The function returns the first matching node or None if no match is found.

Source Code

def get_dbo_usergroup_by_uid(uid):
    """Get a dbo_UserGroup node by its UID"""
    query = """
    MATCH (n:dbo_UserGroup {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_UserGroup node to retrieve. Expected to be a string or integer value that matches the UID property of a node in the Neo4j database. This parameter is used in a Cypher query to perform an exact match lookup.

Return Value

Returns a single dbo_UserGroup node object (typically a dictionary or Neo4j node object) if a matching node is found, or None if no node with the specified UID exists. The returned node contains all properties associated with the dbo_UserGroup node in the database. The function accesses the first element of the result list (result[0]) when results exist.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

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

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

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

# Using get_dbo_usergroup_by_uid
user_group = get_dbo_usergroup_by_uid('12345')

if user_group:
    print(f'Found user group: {user_group}')
else:
    print('User group not found')

# Example with different UID types
user_group_int = get_dbo_usergroup_by_uid(67890)
user_group_str = get_dbo_usergroup_by_uid('admin-group-001')

Best Practices

  • Ensure the run_query function is properly defined and handles Neo4j connection management, including session creation and cleanup
  • Validate the uid parameter before passing it to the function to avoid unnecessary database queries
  • Handle the None return value appropriately in calling code to avoid AttributeError when accessing properties
  • Consider adding error handling for database connection failures or query execution errors
  • Ensure proper indexing on the UID property in Neo4j for optimal query performance
  • The function assumes run_query returns a list; verify this behavior matches your implementation
  • Consider adding type hints for better code documentation (e.g., def get_dbo_usergroup_by_uid(uid: str) -> Optional[Dict])
  • Close Neo4j driver connections properly when the application terminates to avoid resource leaks

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_usergroup_by_id 90.5% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_product_by_uid 79.4% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_usergroup 79.3% similar

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

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_flocks_by_uid 78.0% similar

    Retrieves a single dbo_Flocks 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_concepts_by_uid 77.6% similar

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

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