function get_dbo_establishmentcycles_by_id
Retrieves a single dbo_EstablishmentCycles node from a Neo4j graph database by its unique ID.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
772 - 779
simple
Purpose
This function queries a Neo4j database to fetch a specific establishment cycle record identified by its ID. It's designed for retrieving individual establishment cycle entities from the graph database, returning the complete node if found or None if no matching node exists. This is useful for lookup operations when you need to access a specific establishment cycle's data.
Source Code
def get_dbo_establishmentcycles_by_id(id):
"""Get a dbo_EstablishmentCycles node by its ID"""
query = """
MATCH (n:dbo_EstablishmentCycles {id: $id})
RETURN n
"""
result = run_query(query, {"id": id})
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
id |
- | - | positional_or_keyword |
Parameter Details
id: The unique identifier of the dbo_EstablishmentCycles node to retrieve. Expected to be a value that matches the 'id' property of nodes with the label 'dbo_EstablishmentCycles' in the Neo4j database. Type is not explicitly constrained but should match the type used in the database (typically string or integer).
Return Value
Returns the first matching dbo_EstablishmentCycles node as a dictionary-like object (Neo4j Node object) if found, or None if no node with the specified ID exists. The returned node contains all properties associated with that establishment cycle record in the database.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j connection is configured
from neo4j import GraphDatabase
# Example usage
establishment_cycle = get_dbo_establishmentcycles_by_id(12345)
if establishment_cycle:
print(f"Found establishment cycle: {establishment_cycle}")
# Access node properties
cycle_id = establishment_cycle['id']
# Access other properties as needed
else:
print("Establishment cycle not found")
Best Practices
- Ensure the run_query function is properly defined and handles Neo4j connection management
- Validate the id parameter before calling this function to ensure it's not None or empty
- Handle the None return value appropriately in calling code to avoid AttributeError
- Consider adding error handling for database connection failures
- The function assumes run_query returns a list; ensure this contract is maintained
- For production use, consider adding logging for debugging and monitoring
- Ensure proper indexing on the 'id' property in Neo4j for optimal query performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_establishmentcycles_by_uid 90.6% similar
-
function get_dbo_establishment_by_id 88.2% similar
-
function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 86.2% similar
-
function get_all_dbo_establishmentcycles 85.4% similar
-
function get_dbo_establishment_by_uid 78.2% similar