rails_age 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,67 +0,0 @@
1
- module ApacheAge
2
- class Entity
3
- class << self
4
- def find_by(attributes)
5
- where_clause = attributes.map { |k, v| "find.#{k} = '#{v}'" }.join(' AND ')
6
- handle_find(where_clause)
7
- end
8
-
9
- def find(id)
10
- where_clause = "id(find) = #{id}"
11
- handle_find(where_clause)
12
- end
13
-
14
- private
15
-
16
- def age_graph = 'age_schema'
17
-
18
- def handle_find(where_clause)
19
- # try to find a vertex
20
- match_node = '(find)'
21
- cypher_sql = find_sql(match_node, where_clause)
22
- age_response = execute_find(cypher_sql)
23
-
24
- if age_response.nil?
25
- # if not a vertex try to find an edge
26
- match_edge = '()-[find]->()'
27
- cypher_sql = find_sql(match_edge, where_clause)
28
- age_response = execute_find(cypher_sql)
29
- return nil if age_response.nil?
30
- end
31
-
32
- instantiate_result(age_response)
33
- end
34
-
35
- def execute_find(cypher_sql)
36
- age_result = ActiveRecord::Base.connection.execute(cypher_sql)
37
- return nil if age_result.values.first.nil?
38
-
39
- age_result
40
- end
41
-
42
- def instantiate_result(age_response)
43
- age_type = age_response.values.first.first.split('::').last
44
- json_string = age_response.values.first.first.split('::').first
45
- json_data = JSON.parse(json_string)
46
-
47
- age_label = json_data['label']
48
- attribs = json_data.except('label', 'properties')
49
- .merge(json_data['properties'])
50
- .symbolize_keys
51
-
52
- "#{json_data['label'].gsub('__', '::')}".constantize.new(**attribs)
53
- end
54
-
55
- def find_sql(match_clause, where_clause)
56
- <<-SQL
57
- SELECT *
58
- FROM cypher('#{age_graph}', $$
59
- MATCH #{match_clause}
60
- WHERE #{where_clause}
61
- RETURN find
62
- $$) as (found agtype);
63
- SQL
64
- end
65
- end
66
- end
67
- end
@@ -1,52 +0,0 @@
1
- module ApacheAge
2
- module Vertex
3
- extend ActiveSupport::Concern
4
- # include ApacheAge::Entity
5
-
6
- included do
7
- include ActiveModel::Model
8
- include ActiveModel::Dirty
9
- include ActiveModel::Attributes
10
-
11
- attribute :id, :integer
12
-
13
- extend ApacheAge::ClassMethods
14
- include ApacheAge::CommonMethods
15
- end
16
-
17
- def age_type = 'vertex'
18
-
19
- # AgeSchema::Nodes::Company.create(company_name: 'Bedrock Quarry')
20
- # SELECT *
21
- # FROM cypher('age_schema', $$
22
- # CREATE (company:Company {company_name: 'Bedrock Quarry'})
23
- # RETURN company
24
- # $$) as (Company agtype);
25
- def create_sql
26
- alias_name = age_alias || age_label.downcase
27
- <<-SQL
28
- SELECT *
29
- FROM cypher('#{age_graph}', $$
30
- CREATE (#{alias_name}#{self})
31
- RETURN #{alias_name}
32
- $$) as (#{age_label} agtype);
33
- SQL
34
- end
35
-
36
- # So far just properties of string type with '' around them
37
- def update_sql
38
- alias_name = age_alias || age_label.downcase
39
- set_caluse =
40
- age_properties.map { |k, v| v ? "#{alias_name}.#{k} = '#{v}'" : "#{alias_name}.#{k} = NULL" }.join(', ')
41
- <<-SQL
42
- SELECT *
43
- FROM cypher('#{age_graph}', $$
44
- MATCH (#{alias_name}:#{age_label})
45
- WHERE id(#{alias_name}) = #{id}
46
- SET #{set_caluse}
47
- RETURN #{alias_name}
48
- $$) as (#{age_label} agtype);
49
- SQL
50
- end
51
- end
52
- end