function get_all_dbo_establishment
Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_Establishment' with a configurable limit on the number of results returned.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
724 - 731
simple
Purpose
This function is designed to fetch establishment entities from a Neo4j graph database. It's useful for retrieving business, organization, or location data stored as dbo_Establishment nodes. The function provides pagination control through the limit parameter, making it suitable for both small-scale queries and large dataset exploration. It relies on an external 'run_query' function to execute the Cypher query against the database.
Source Code
def get_all_dbo_establishment(limit=100):
"""Return dbo_Establishment nodes (limited to 25)"""
query = """
MATCH (n:dbo_Establishment)
RETURN n
LIMIT $limit
"""
return run_query(query, {"limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
limit |
- | 100 | positional_or_keyword |
Parameter Details
limit: Integer value that controls the maximum number of dbo_Establishment nodes to return from the database. Default is 100. Note: The docstring incorrectly states the limit is 25, but the actual default is 100. This parameter is passed to the Cypher query's LIMIT clause to prevent overwhelming results from large datasets.
Return Value
Returns the result of the 'run_query' function execution. The exact return type depends on the implementation of 'run_query', but typically would be a list of Neo4j node objects or dictionaries representing dbo_Establishment nodes. Each node would contain properties associated with the establishment entities stored in the database. If no nodes match, an empty collection would be returned.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
from neo4j import GraphDatabase
# Assuming run_query is defined elsewhere in your codebase
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()
# Get default 100 establishments
establishments = get_all_dbo_establishment()
# Get only 10 establishments
establishments_limited = get_all_dbo_establishment(limit=10)
# Process results
for establishment in establishments:
print(establishment)
Best Practices
- Always specify an appropriate limit value based on your use case to avoid memory issues with large datasets
- The docstring contains incorrect information (states limit is 25 but default is 100) - this should be corrected in production code
- Ensure the 'run_query' function properly handles database connections and closes them to prevent connection leaks
- Consider adding error handling for database connection failures or query execution errors
- For production use, consider adding parameter validation to ensure limit is a positive integer
- Consider adding pagination support (offset parameter) for iterating through large result sets
- The function assumes 'run_query' is available in scope - ensure proper import or definition
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_all_dbo_establishmentcycles 87.9% similar
-
function get_dbo_establishment_by_id 81.7% similar
-
function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 81.6% similar
-
function get_dbo_houses_with_references_establishment_dbo_establishment 81.3% similar
-
function get_dbo_tnv_with_references_establishment_dbo_establishment 78.8% similar