Class: Cyrel::Clause::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/cyrel/clause/create.rb

Overview

Represents a CREATE clause in a Cypher query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Create

Returns a new instance of Create.

Parameters:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cyrel/clause/create.rb', line 11

def initialize(pattern)
  # Ensure pattern is a valid type for CREATE
  unless pattern.is_a?(Cyrel::Pattern::Path) || pattern.is_a?(Cyrel::Pattern::Node) || pattern.is_a?(Cyrel::Pattern::Relationship)
    raise ArgumentError,
          "CREATE pattern must be a Cyrel::Pattern::Path, Node, or Relationship, got #{pattern.class}"
  end

  # NOTE: Creating relationships between existing nodes requires coordination.
  # The pattern itself should reference existing aliases defined in a preceding MATCH/MERGE.
  # The Query object might need to track defined aliases if validation is needed here.
  @pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



7
8
9
# File 'lib/cyrel/clause/create.rb', line 7

def pattern
  @pattern
end

Instance Method Details

#render(query) ⇒ String

Renders the CREATE clause.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering the pattern.

Returns:

  • (String)

    The Cypher string fragment for the clause.



27
28
29
30
# File 'lib/cyrel/clause/create.rb', line 27

def render(query)
  pattern_string = @pattern.render(query)
  "CREATE #{pattern_string}"
end