function get_dbo_flocks_with_references_flocktypes_dbo_flocktypes
Queries a Neo4j graph database to retrieve dbo_FlockTypes nodes that are connected to a specific dbo_Flocks node via a REFERENCES_FLOCKTYPES relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1897 - 1904
simple
Purpose
This function is designed to traverse a graph database relationship between Flocks and FlockTypes entities. It retrieves all FlockTypes associated with a given Flock identified by source_id, with a configurable limit on the number of results returned. This is useful for understanding what types are associated with a particular flock in a database schema that models livestock or bird management systems.
Source Code
def get_dbo_flocks_with_references_flocktypes_dbo_flocktypes(source_id, limit=100):
"""Get dbo_FlockTypes nodes connected to a dbo_Flocks via REFERENCES_FLOCKTYPES"""
query = """
MATCH (source:dbo_Flocks {id: $source_id})-[r:REFERENCES_FLOCKTYPES]->(target:dbo_FlockTypes)
RETURN target
LIMIT $limit
"""
return run_query(query, {"source_id": source_id, "limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
source_id |
- | - | positional_or_keyword |
limit |
- | 100 | positional_or_keyword |
Parameter Details
source_id: The unique identifier of the dbo_Flocks node from which to start the traversal. This should be a value that matches the 'id' property of a dbo_Flocks node in the Neo4j database. Expected type is typically string or integer depending on the database schema.
limit: Maximum number of dbo_FlockTypes nodes to return. Defaults to 100. This parameter controls query performance and result set size. Must be a positive integer. Setting this too high may impact performance on large datasets.
Return Value
Returns the result of run_query() function, which typically returns a list of Neo4j records containing the target dbo_FlockTypes nodes. Each record represents a dbo_FlockTypes node with all its properties. The exact structure depends on the run_query() implementation, but commonly returns a list of dictionaries or Neo4j Record objects. Returns an empty list if no matching relationships are found or if the source_id doesn't exist.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
from neo4j import GraphDatabase
# Assuming run_query is defined elsewhere in the module
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['target'] for record in result]
driver.close()
# Get flock types for a specific flock
flock_id = 'FLOCK_12345'
flock_types = get_dbo_flocks_with_references_flocktypes_dbo_flocktypes(flock_id, limit=50)
# Process the results
for flock_type in flock_types:
print(f"Flock Type: {flock_type}")
# Get all flock types (up to default limit of 100)
all_flock_types = get_dbo_flocks_with_references_flocktypes_dbo_flocktypes('FLOCK_67890')
Best Practices
- Always validate that source_id exists before calling this function to avoid unnecessary database queries
- Consider adjusting the limit parameter based on expected result set size to optimize performance
- Ensure proper error handling around the run_query() call to catch database connection issues
- Use connection pooling in the run_query() implementation for better performance in production environments
- Consider adding pagination if you need to retrieve more than the limit allows
- Validate that the run_query() function properly closes database connections to prevent resource leaks
- Consider adding indexes on the 'id' property of dbo_Flocks nodes for better query performance
- Be aware that this function depends on the external run_query() function which must be properly implemented and available
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_houses_with_references_flocktypes_dbo_flocktypes 89.9% similar
-
function get_all_dbo_flocktypes 88.7% similar
-
function get_dbo_establishment_with_references_flocktypes_dbo_flocktypes 88.3% similar
-
function get_dbo_flocktypes_by_id 86.1% similar
-
function get_dbo_treatments_with_references_flocks_dbo_flocks 82.1% similar