Class: Cyrel::Clause::Merge

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

Overview

Represents a MERGE clause in a Cypher query. Used to find a pattern or create it if it doesn’t exist.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Merge

Returns a new instance of Merge.

Parameters:



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

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

  @pattern = pattern
end

Instance Attribute Details

#patternObject (readonly)

Returns the value of attribute pattern.



8
9
10
# File 'lib/cyrel/clause/merge.rb', line 8

def pattern
  @pattern
end

Instance Method Details

#render(query) ⇒ String

Renders the MERGE 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
31
# File 'lib/cyrel/clause/merge.rb', line 27

def render(query)
  pattern_string = @pattern.render(query)
  "MERGE #{pattern_string}"
  # TODO: Append ON CREATE SET / ON MATCH SET rendering when implemented.
end