rails_age 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -7
- data/lib/apache_age/entities/class_methods.rb +2 -2
- data/lib/apache_age/entities/query_builder.rb +97 -13
- data/lib/rails_age/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8bae6566d3be3dc932bc834d67b969ddab46efb5bc72dfde5b245a861f9c09f
|
4
|
+
data.tar.gz: 04ab7c0d236560abefbe9d637a24e5e027ada6a2f3c0279d4aace865262c5808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e2b16c1934dbdf79dce10028ee5d6066e93416a0ea2a31f378b2239db72383b11dec44a892a254721c75130f2b0fad5c4ab4a4dda0bdbf747ecb66bc695c8b7
|
7
|
+
data.tar.gz: 5883fcd0e9a36c965683ec01702b9a8e6b8d31e66d991ef2331c21ab11aa49c894965f666937d456dbd5fc7aaea1b35577f9f9c9b8115c4775a83bf18eed4354
|
data/CHANGELOG.md
CHANGED
@@ -35,21 +35,22 @@ breaking change?: namespaces (by default) will use their own schema? (add to dat
|
|
35
35
|
- **Age Path** - nodes and edges combined
|
36
36
|
* add `rails generate apache_age:path_scaffold HasJob employee_role start_node:person end_node:company`
|
37
37
|
|
38
|
+
## VERSION 0.6.4 - 2024-xx-xx
|
38
39
|
|
39
|
-
|
40
|
+
- **Query Sanitize**:
|
41
|
+
* reject attributes not defined in model (throw error?)
|
42
|
+
* allow and sanitize query strings with multiple attributes, ie: `Person.where("find.first_name = ? AND find.last_name = ?", 'John', 'Doe')`
|
43
|
+
|
44
|
+
## VERSION 0.6.3 - 2024-10-27
|
40
45
|
|
41
46
|
- **Query Sanitize**:
|
42
|
-
* reject attributes not defined in model
|
43
47
|
* sanitize strings using: id(find) = ?, 23 & find.first_name = ?, 'John'
|
48
|
+
NOTE: this sanitization only works (so far) for strings containing ONE attribute. ie: `Person.where("find.first_name = ?", 'John')` or `Person.where("first_name = ?", 'John')` works but `Person.where("find.first_name = ? AND find.last_name = ?", 'John', 'Doe')` does not yet work
|
44
49
|
|
45
50
|
## VERSION 0.6.2 - 2024-09-30
|
46
51
|
|
47
52
|
- **Query Sanitize**
|
48
|
-
*
|
49
|
-
|
50
|
-
- **TODO**:
|
51
|
-
* reject attributes not defined in model
|
52
|
-
* sanitize strings using: id(find) = ?, 23 & find.first_name = ?, 'John'
|
53
|
+
* hash queries sanitized
|
53
54
|
|
54
55
|
## VERSION 0.6.1 - 2024-09-29
|
55
56
|
|
@@ -41,32 +41,116 @@ module ApacheAge
|
|
41
41
|
self
|
42
42
|
end
|
43
43
|
|
44
|
-
# TODO: need to handle string inputs too: instead of: \
|
45
|
-
# "id(find) = #{id}" & "find.name = #{name}"
|
46
|
-
# we can have: "id(find) = ?", id & "find.name = ?", name
|
47
|
-
# ActiveRecord::Base.sanitize_sql([query_string, v])
|
48
|
-
def where(
|
49
|
-
return self if
|
44
|
+
# # TODO: need to handle string inputs too: instead of: \
|
45
|
+
# # "id(find) = #{id}" & "find.name = #{name}"
|
46
|
+
# # we can have: "id(find) = ?", id & "find.name = ?", name
|
47
|
+
# # ActiveRecord::Base.sanitize_sql([query_string, v])
|
48
|
+
def where(*args)
|
49
|
+
return self if args.blank?
|
50
50
|
|
51
51
|
@where_clauses <<
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
# not able to sanitize the query string in this case
|
53
|
+
# ["first_name = 'Barney'"]
|
54
|
+
if args.length == 1 && args.first.is_a?(String)
|
55
|
+
string_query = args.first
|
56
|
+
if string_query.include?('id = ?')
|
57
|
+
"id(find) = ?"
|
58
|
+
elsif string_query.include?('id(') || string_query.include?('find.')
|
59
|
+
string_query
|
55
60
|
else
|
56
|
-
"find.#{
|
61
|
+
"find.#{string_query}"
|
57
62
|
end
|
58
|
-
|
63
|
+
|
64
|
+
# Handling & sanitizing parameterized string queries
|
65
|
+
elsif args.length > 1 && args.first.is_a?(String)
|
66
|
+
raw_query_string = args.first
|
67
|
+
query_string =
|
68
|
+
if raw_query_string.include?('id = ?')
|
69
|
+
"id(find) = ?"
|
70
|
+
elsif raw_query_string.include?('id(') || raw_query_string.include?('find.')
|
71
|
+
raw_query_string
|
72
|
+
else
|
73
|
+
"find.#{raw_query_string}"
|
74
|
+
end
|
75
|
+
values = args[1..-1]
|
76
|
+
ActiveRecord::Base.sanitize_sql_array([query_string, *values])
|
77
|
+
|
78
|
+
# Hashes are sanitized in the model class
|
79
|
+
# [{:first_name=>"Barney", :last_name=>"Rubble", :gender=>"male"}]
|
80
|
+
elsif args.first.is_a?(Hash)
|
81
|
+
attributes = args.first
|
59
82
|
edge_keys = [:start_id, :start_node, :end_id, :end_node]
|
60
83
|
if edge_keys.any? { |key| attributes.include?(key) }
|
61
|
-
model_class.send(:where_edge_clause, attributes)
|
84
|
+
model_class.send(:where_edge_clause, **attributes)
|
62
85
|
else
|
63
|
-
model_class.send(:where_node_clause, attributes)
|
86
|
+
model_class.send(:where_node_clause, **attributes)
|
64
87
|
end
|
88
|
+
|
89
|
+
else
|
90
|
+
raise ArgumentError, "Invalid arguments for `where` method"
|
65
91
|
end
|
66
92
|
|
67
93
|
self
|
68
94
|
end
|
69
95
|
|
96
|
+
# # where is sanitized in the model class with hash values
|
97
|
+
# def where(attributes)
|
98
|
+
# return self if attributes.blank?
|
99
|
+
|
100
|
+
# @where_clauses <<
|
101
|
+
# if attributes.is_a?(String)
|
102
|
+
# puts "HANDLE PURE STRING QUERIES"
|
103
|
+
# if attributes.include?('id(') || attributes.include?('find.')
|
104
|
+
# attributes
|
105
|
+
# else
|
106
|
+
# "find.#{attributes}"
|
107
|
+
# end
|
108
|
+
# else
|
109
|
+
# puts "HANDLE HASHES"
|
110
|
+
# pp attributes
|
111
|
+
# edge_keys = [:start_id, :start_node, :end_id, :end_node]
|
112
|
+
# if edge_keys.any? { |key| attributes.include?(key) }
|
113
|
+
# puts "HANDLE EDGE CLAUSES"
|
114
|
+
# model_class.send(:where_edge_clause, attributes)
|
115
|
+
# else
|
116
|
+
# puts "HANDLE NODE CLAUSES"
|
117
|
+
# model_class.send(:where_node_clause, attributes)
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
|
121
|
+
# self
|
122
|
+
# end
|
123
|
+
|
124
|
+
# # Pre-sanitize where statements
|
125
|
+
# # def where(*args)
|
126
|
+
# # return self if args.blank?
|
127
|
+
|
128
|
+
# # # Handling parameterized query strings with values
|
129
|
+
# # if args.length == 1 && args.first.is_a?(Hash)
|
130
|
+
# # # If a hash of attributes is provided, use the existing logic
|
131
|
+
# # attributes = args.first
|
132
|
+
# # edge_keys = [:start_id, :start_node, :end_id, :end_node]
|
133
|
+
# # if edge_keys.any? { |key| attributes.include?(key) }
|
134
|
+
# # @where_clauses << model_class.send(:where_edge_clause, attributes)
|
135
|
+
# # else
|
136
|
+
# # @where_clauses << model_class.send(:where_node_clause, attributes)
|
137
|
+
# # end
|
138
|
+
# # elsif args.length > 1 && args.first.is_a?(String)
|
139
|
+
# # # If a query string with placeholders and values is provided
|
140
|
+
# # query_string = args.first
|
141
|
+
# # values = args[1..-1]
|
142
|
+
# # sanitized_query = ActiveRecord::Base.send(:sanitize_sql_array, [query_string, *values])
|
143
|
+
# # @where_clauses << sanitized_query
|
144
|
+
# # elsif args.length == 1 && args.first.is_a?(String)
|
145
|
+
# # # If a single string is provided, use it directly (assuming it is already sanitized or trusted)
|
146
|
+
# # @where_clauses << args.first
|
147
|
+
# # else
|
148
|
+
# # raise ArgumentError, "Invalid arguments for `where` method"
|
149
|
+
# # end
|
150
|
+
|
151
|
+
# # self
|
152
|
+
# # end
|
153
|
+
|
70
154
|
# New return method
|
71
155
|
def return(*variables)
|
72
156
|
return self if variables.blank?
|
data/lib/rails_age/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_age
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|