Module: ApacheAge::Entities::Node
Instance Method Summary collapse
- #age_type ⇒ Object
-
#create_sql ⇒ Object
AgeSchema::Nodes::Company.create(company_name: 'Bedrock Quarry') SELECT * FROM cypher('age_schema', $$ CREATE (company:Company 'Bedrock Quarry') RETURN company $$) as (Company agtype);.
-
#update_sql ⇒ Object
So far just properties of string type with '' around them.
Instance Method Details
#age_type ⇒ Object
19 |
# File 'lib/apache_age/entities/node.rb', line 19 def age_type = 'vertex' |
#create_sql ⇒ Object
AgeSchema::Nodes::Company.create(company_name: 'Bedrock Quarry') SELECT * FROM cypher('age_schema', $$ CREATE (company:Company '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(', ') <<~SQL.squish SELECT * FROM cypher('#{age_graph}', $$ CREATE (#{alias_name}:#{age_label} {#{sanitized_properties}}) RETURN #{alias_name} $$) as (#{age_label} agtype); SQL end |
#update_sql ⇒ Object
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]) <<-SQL SELECT * FROM cypher('#{age_graph}', $$ MATCH (#{alias_name}:#{age_label}) WHERE id(#{alias_name}) = #{sanitized_id} SET #{sanitized_set_clause} RETURN #{alias_name} $$) as (#{age_label} agtype); SQL end |