🔍 Code Extractor

function create_dbo_establishmentcycles

Maturity: 46

Creates a new node labeled 'dbo_EstablishmentCycles' in a Neo4j graph database with the specified properties and returns the created node.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
790 - 799
Complexity:
simple

Purpose

This function provides a programmatic way to insert establishment cycle records into a Neo4j graph database. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query, and returns the newly created node. This is useful for applications managing establishment lifecycle data in a graph database structure.

Source Code

def create_dbo_establishmentcycles(properties):
    """Create a new dbo_EstablishmentCycles node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:dbo_EstablishmentCycles)
    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 dbo_EstablishmentCycles node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, dates, etc.). Example: {'cycle_id': 123, 'name': 'Q1 2024', 'start_date': '2024-01-01'}

Return Value

Returns the first node from the query result if the creation was successful, typically a dictionary-like object representing the created Neo4j node with all its properties. Returns None if the query execution fails or returns no results. The returned node object will contain all properties that were set during creation.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j is configured

# Define properties for the new establishment cycle
properties = {
    'cycle_id': 12345,
    'establishment_name': 'Main Office',
    'start_date': '2024-01-01',
    'end_date': '2024-12-31',
    'status': 'active'
}

# Create the node
result = create_dbo_establishmentcycles(properties)

if result:
    print(f"Successfully created node: {result}")
else:
    print("Failed to create node")

Best Practices

  • Ensure the properties dictionary contains valid data types supported by Neo4j before calling this function
  • Validate property names to avoid Cypher injection vulnerabilities, especially if properties come from user input
  • The function depends on an external run_query function which must be properly implemented with error handling and connection management
  • Consider adding input validation to check if properties dictionary is empty or None before executing the query
  • Use parameterized queries (as this function does with ${prop}) to prevent injection attacks
  • Implement proper error handling around the function call to catch database connection issues or query execution failures
  • Consider adding transaction management for consistency when creating multiple related nodes
  • Be aware that this function creates nodes without checking for duplicates; implement uniqueness constraints at the database level if needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_dbo_establishment 88.9% similar

    Creates a new dbo_Establishment node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_establishment_relationship_v4 81.4% similar

    Creates a REFERENCES_ESTABLISHMENT relationship in a Neo4j graph database between a dbo_EstablishmentCycles node and a dbo_Establishment node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishmentcycles_with_references_establishment_dbo_establishment 79.1% similar

    Queries a Neo4j graph database to retrieve dbo_Establishment nodes that are connected to a specific dbo_EstablishmentCycles node through a REFERENCES_ESTABLISHMENT relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_establishmentcycles_by_id 77.9% similar

    Retrieves a single dbo_EstablishmentCycles node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_establishmentcycles 75.0% similar

    Retrieves all nodes of type dbo_EstablishmentCycles from a Neo4j graph database with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse