Module: ApacheAge::Entities::Node

Extended by:
ActiveSupport::Concern
Included in:
Node
Defined in:
lib/apache_age/entities/node.rb

Instance Method Summary collapse

Instance Method Details

#age_typeObject



19
# File 'lib/apache_age/entities/node.rb', line 19

def age_type = 'vertex'

#create_sqlObject

AgeSchema::Nodes::Company.create(company_name: ‘Bedrock Quarry’) SELECT * FROM cypher(‘age_schema’, $$

CREATE (company:Company {company_name: 'Bedrock Quarry'})

RETURN company $$) as (Company agtype);



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/apache_age/entities/node.rb', line 27

def create_sql
  alias_name = age_alias || age_label.downcase
  sanitized_properties =
    self
      .to_h.reject { |k, v| k == :id }.reject { |k, v| v.nil? }
      .map { |k, v| "#{k}: #{ActiveRecord::Base.sanitize_sql(["?", v])}" }
      .join(', ')

  "    SELECT *\n    FROM cypher('\#{age_graph}', $$\n        CREATE (\#{alias_name}:\#{age_label} {\#{sanitized_properties}})\n    RETURN \#{alias_name}\n    $$) as (\#{age_label} agtype);\n  SQL\nend\n".squish

#update_sqlObject

So far just properties of string type with ” around them



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/apache_age/entities/node.rb', line 45

def update_sql
  alias_name = ActiveRecord::Base.sanitize_sql_like(age_alias || age_label.downcase)
  sanitized_set_clause = age_properties.map do |k, v|
    if v
      sanitized_value = ActiveRecord::Base.sanitize_sql(["?", v])
      "#{alias_name}.#{k} = #{sanitized_value}"
    else
      "#{alias_name}.#{k} = NULL"
    end
  end.join(', ')

  sanitized_id = ActiveRecord::Base.sanitize_sql(["?", id])

  "    SELECT *\n    FROM cypher('\#{age_graph}', $$\n        MATCH (\#{alias_name}:\#{age_label})\n        WHERE id(\#{alias_name}) = \#{sanitized_id}\n        SET \#{sanitized_set_clause}\n        RETURN \#{alias_name}\n    $$) as (\#{age_label} agtype);\n  SQL\nend\n"