🔍 Code Extractor

function get_dbo_product_by_uid

Maturity: 41

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

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
1015 - 1022
Complexity:
simple

Purpose

This function queries a Neo4j database to find and return a specific product node labeled as 'dbo_Product' using its UID property. It's designed for retrieving individual product records from a graph database, typically used in e-commerce, inventory management, or product catalog systems where products are stored as graph nodes. The function returns the first matching node or None if no product with the given UID exists.

Source Code

def get_dbo_product_by_uid(uid):
    """Get a dbo_Product node by its UID"""
    query = """
    MATCH (n:dbo_Product {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_Product node to retrieve. Expected to be a string or integer value that matches the UID property of a product node in the Neo4j database. This should be a valid, existing UID for successful retrieval.

Return Value

Returns a dictionary-like object representing the dbo_Product node if found, containing all properties of the matched node. Returns None if no product with the specified UID exists in the database. The exact structure depends on the properties stored in the dbo_Product nodes (e.g., name, price, description, etc.).

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, params):
    with driver.session() as session:
        result = session.run(query, params)
        return [record['n'] for record in result]

# Using get_dbo_product_by_uid
product_uid = 'PROD-12345'
product = get_dbo_product_by_uid(product_uid)

if product:
    print(f'Found product: {product}')
else:
    print('Product not found')

# Clean up
driver.close()

Best Practices

  • Ensure the 'run_query' helper function is properly implemented with error handling and connection management
  • Validate the uid parameter before passing it to prevent injection attacks or invalid queries
  • Consider adding error handling for database connection failures or query execution errors
  • The function assumes run_query returns a list; ensure this contract is maintained
  • Create an index on the UID property in Neo4j for optimal query performance: CREATE INDEX ON :dbo_Product(UID)
  • Consider adding type hints for better code documentation: def get_dbo_product_by_uid(uid: str) -> Optional[Dict]
  • Handle the case where multiple nodes might have the same UID (though UIDs should be unique)
  • Close database connections properly when done with queries to prevent resource leaks

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_product_by_id 87.7% similar

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

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

    Retrieves a single dbo_UserGroup 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_tnv_by_uid 76.1% similar

    Retrieves a single dbo_TNV 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 75.7% 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
  • function get_dbo_flocks_by_uid 75.4% 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
← Back to Browse