function create_dbo_interventionprotocolflocks
Creates a new node labeled 'dbo_InterventionProtocolFlocks' in a Neo4j graph database with the specified properties.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
946 - 955
simple
Purpose
This function is designed to insert a new intervention protocol flocks entity into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query, and returns the created node. This is useful for managing intervention protocols related to flocks in agricultural, veterinary, or epidemiological applications.
Source Code
def create_dbo_interventionprotocolflocks(properties):
"""Create a new dbo_InterventionProtocolFlocks node"""
props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
query = f"""
CREATE (n:dbo_InterventionProtocolFlocks)
SET {props_list}
RETURN n
"""
result = run_query(query, properties)
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
properties |
- | - | positional_or_keyword |
Parameter Details
properties: A dictionary containing key-value pairs representing the properties to be set on the new node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, etc.). Example: {'name': 'Protocol A', 'date': '2024-01-01', 'flock_id': 123}
Return Value
Returns the created Neo4j node object (first element from the result list) if the creation was successful, or None if the query returned no results. The node object typically contains all properties set during creation along with Neo4j internal identifiers.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query function is defined and Neo4j is configured
from neo4j import GraphDatabase
# Define the run_query function (example implementation)
def run_query(query, params=None):
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
with driver.session() as session:
result = session.run(query, params or {})
return [record['n'] for record in result]
driver.close()
# Create a new intervention protocol flocks node
properties = {
'protocol_name': 'Vaccination Protocol A',
'flock_id': 'FLOCK-001',
'intervention_date': '2024-01-15',
'status': 'active'
}
node = create_dbo_interventionprotocolflocks(properties)
if node:
print(f'Successfully created node: {node}')
else:
print('Failed to create node')
Best Practices
- Ensure the properties dictionary contains only valid property names without special characters that could break the Cypher query
- Validate and sanitize input properties before passing them to this function to prevent injection attacks
- The function relies on parameterized queries which helps prevent Cypher injection, but property keys are directly interpolated into the query string
- Consider adding error handling around the run_query call to catch database connection or query execution errors
- Ensure the run_query function is properly implemented with connection pooling and error handling
- Be aware that property keys are used directly in the SET clause - avoid using reserved Cypher keywords as property names
- Consider adding validation to ensure properties dictionary is not empty before creating the node
- The function assumes the dbo_InterventionProtocolFlocks label exists in your Neo4j schema design
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function create_dbo_interventionprotocols 82.6% similar
-
function create_references_flocks_relationship_v1 82.3% similar
-
function create_references_interventionprotocols_relationship 81.9% similar
-
function create_dbo_flocks 81.7% similar
-
function get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks 81.3% similar