function get_dbo_houses_by_uid
Retrieves a single dbo_Houses node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
898 - 905
simple
Purpose
This function queries a Neo4j database to fetch a specific house record from the dbo_Houses node collection. It's designed for retrieving individual house entities when the UID is known, typically used in applications that need to look up house details by a unique identifier. The function returns the first matching result or None if no house with the given UID exists.
Source Code
def get_dbo_houses_by_uid(uid):
"""Get a dbo_Houses node by its UID"""
query = """
MATCH (n:dbo_Houses {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_Houses node to retrieve. Expected to be a string or integer value that matches the UID property stored in the Neo4j database. This should be a valid, existing UID for a house record.
Return Value
Returns a dictionary-like object representing the dbo_Houses node if found, containing all properties of the matched node. Returns None if no node with the specified UID exists. The exact structure depends on the properties stored in the dbo_Houses nodes in the database.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
# Example 1: Retrieve a house by UID
house = get_dbo_houses_by_uid('12345')
if house:
print(f"Found house: {house}")
else:
print("House not found")
# Example 2: Handle missing house
uid_to_find = 'abc-123'
house_data = get_dbo_houses_by_uid(uid_to_find)
if house_data is None:
print(f"No house found with UID: {uid_to_find}")
else:
# Access house properties
print(f"House details: {house_data['n']}")
Best Practices
- Always check if the return value is None before accessing properties to avoid AttributeError
- Ensure the UID parameter matches the data type stored in the Neo4j database (string vs integer)
- The function depends on an external run_query function which must be properly implemented with error handling and connection management
- Consider adding input validation for the uid parameter to prevent injection attacks or invalid queries
- Ensure proper Neo4j connection pooling and session management in the run_query function
- The function assumes the UID property is unique; if multiple nodes could have the same UID, only the first result is returned
- Consider adding logging for debugging database queries and connection issues
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepthouses_by_uid 90.5% similar
-
function get_dbo_houses_by_id 88.5% similar
-
function get_dbo_concepthouses_by_id 81.3% similar
-
function get_dbo_usergroup_by_uid 77.6% similar
-
function get_dbo_flocks_by_uid 77.4% similar