function get_dbo_tnv_by_uid
Retrieves a single dbo_TNV node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1054 - 1061
simple
Purpose
This function queries a Neo4j database to find and return a specific dbo_TNV node based on its UID property. It's designed for retrieving individual TNV (likely a domain-specific entity type) records when the exact UID is known. The function returns the first matching node or None if no match is found.
Source Code
def get_dbo_tnv_by_uid(uid):
"""Get a dbo_TNV node by its UID"""
query = """
MATCH (n:dbo_TNV {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_TNV node to retrieve. Expected to be a string or numeric value that matches the UID property stored in the Neo4j database. This should be a valid, existing UID for a dbo_TNV node.
Return Value
Returns the first dbo_TNV node object that matches the provided UID, or None if no matching node is found. The node object is typically a dictionary-like structure containing all properties of the matched Neo4j node. The return type is either a Neo4j node record or None.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
# Example run_query implementation:
def run_query(query, params):
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
with driver.session() as session:
result = session.run(query, params)
return [record['n'] for record in result]
driver.close()
# Using get_dbo_tnv_by_uid
uid_to_find = '12345'
tnv_node = get_dbo_tnv_by_uid(uid_to_find)
if tnv_node:
print(f'Found TNV node: {tnv_node}')
else:
print('No TNV node found with that UID')
Best Practices
- Ensure the run_query 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
- The function assumes run_query returns a list; ensure this contract is maintained
- Close Neo4j driver connections properly in the run_query implementation to prevent resource leaks
- Consider adding logging for debugging purposes when nodes are not found
- If UIDs are expected to be unique, this function's behavior is correct; otherwise, consider that only the first match is returned
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_tnv_by_id 90.9% similar
-
function get_all_dbo_tnv 79.2% similar
-
function get_dbo_flocktypes_by_uid 76.2% similar
-
function get_dbo_usergroup_by_uid 76.1% similar
-
function get_dbo_product_by_uid 76.1% similar