activerecord-hierarchical_query 1.2.1 → 1.4.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18f95128fd462bc6f9c7ea0ff645a4015b812c839058470b4ffa90d3f9086f94
4
- data.tar.gz: 550f1bd66253046d7f1529dd35948deb4aae02195189e62d6e471bb9398323be
3
+ metadata.gz: d042af24e9fdd0b4aa819e458ee6ce01f6003a74319c89bb01c51c8d314ee23a
4
+ data.tar.gz: 7c3f983e9f6181d18414af603bc174d72f2baca983c10cd3cdd61425083e33aa
5
5
  SHA512:
6
- metadata.gz: 898cec660309a3677f0b5c570fa7d8c368281b9a8d1713e38c21b1c1c1a022fe9f5cea21cee4c5a3f90dafd14fc3c4c25f168be7412c1b17b1cbaa9e4c713e83
7
- data.tar.gz: a54b8e2d64dd6249ed4b80a7140849d2de1d74733c5a9c16796d8b5e8575077f4481edf23baf787f3544a82b1d9f14dd02db51b6f85bc99e32f942d62f829544
6
+ metadata.gz: 8de0cf1db7102615b812f1edd12a8c3409475713eb1852e46500806c44a50bee7f00e57779943e477b860f206fcb1350115a6f7ea3064de4ca3432a753286d53
7
+ data.tar.gz: 957277b46f4a99e87d0c3a1fdeb92216283a0071150a43687e995ef9fc4216c8fb01cbb25d1caec4946aaa0a21ddfbf0540dfb6950356ddffda0e93b8739b741
data/README.md CHANGED
@@ -13,21 +13,13 @@ in hierarchical order using hierarchical query builder.
13
13
 
14
14
  ## Requirements
15
15
 
16
- * ActiveRecord >= 5.0, <= 6.0
17
- * PostgreSQL >= 8.4
18
- * Postgres Gem >= 0.21, < 1.2
16
+ - ActiveRecord >= 5.0, < 7.1
17
+ - PostgreSQL >= 8.4
18
+ - Postgres Gem >= 0.21, < 1.3
19
19
 
20
20
  Note that though PostgresSQL 8.4 and up should work, this library
21
21
  is tested on PostgresSQL 10.5.
22
22
 
23
- ### Rails Version
24
-
25
- **Rails 4 support has ended.**
26
-
27
- If you have trouble with Rails 5.1 or 5.0, try upgrading to Rails 5.2
28
- first. Rails 6 should work, but please report issues immediately as
29
- support is recent.
30
-
31
23
  ## In a nutshell
32
24
 
33
25
  ### Traverse trees
@@ -130,13 +122,15 @@ end
130
122
 
131
123
  Hierarchical queries consist of these important clauses:
132
124
 
133
- * **START WITH** clause
125
+ - **START WITH** clause
134
126
 
135
127
  This clause specifies the root row(s) of the hierarchy.
136
- * **CONNECT BY** clause
128
+
129
+ - **CONNECT BY** clause
137
130
 
138
131
  This clause specifies relationship between parent rows and child rows of the hierarchy.
139
- * **ORDER SIBLINGS** clause
132
+
133
+ - **ORDER SIBLINGS** clause
140
134
 
141
135
  This clause specifies an order of rows in which they appear on each hierarchy level.
142
136
 
@@ -144,16 +138,16 @@ These terms are borrowed from [Oracle hierarchical queries syntax](http://docs.o
144
138
 
145
139
  Hierarchical queries are processed as follows:
146
140
 
147
- * First, root rows are selected -- those rows that satisfy `START WITH` condition in
141
+ - First, root rows are selected -- those rows that satisfy `START WITH` condition in
148
142
  order specified by `ORDER SIBLINGS` clause. In example above it's specified by
149
143
  statements `query.start_with(parent_id: nil)` and `query.order_siblings(:name)`.
150
144
 
151
- * Second, child rows for each root rows are selected. Each child row must satisfy
145
+ - Second, child rows for each root rows are selected. Each child row must satisfy
152
146
  condition specified by `CONNECT BY` clause with respect to one of the root rows
153
147
  (`query.connect_by(id: :parent_id)` in example above). Order of child rows is
154
148
  also specified by `ORDER SIBLINGS` clause.
155
149
 
156
- * Successive generations of child rows are selected with respect to `CONNECT BY` clause.
150
+ - Successive generations of child rows are selected with respect to `CONNECT BY` clause.
157
151
  First the children of each row selected in step 2 selected, then the children of those
158
152
  children and so on.
159
153
 
@@ -342,7 +336,7 @@ ORDER BY "categories__recursive"."__order_column" ASC
342
336
  ```
343
337
 
344
338
  If you want to use a `LEFT OUTER JOIN` instead of an `INNER JOIN`,
345
- add a query option for `outer_join_hierarchical`. This
339
+ add a query option for `outer_join_hierarchical`. This
346
340
  option allows the query to return non-hierarchical entries:
347
341
 
348
342
  ```ruby
@@ -359,10 +353,10 @@ key of the main table to another column:
359
353
 
360
354
  ## Related resources
361
355
 
362
- * [About hierarchical queries (Wikipedia)](http://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL)
363
- * [Hierarchical queries in Oracle](http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm)
364
- * [Recursive queries in PostgreSQL](http://www.postgresql.org/docs/9.3/static/queries-with.html)
365
- * [Using Recursive SQL with ActiveRecord trees](http://hashrocket.com/blog/posts/recursive-sql-in-activerecord)
356
+ - [About hierarchical queries (Wikipedia)](http://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL)
357
+ - [Hierarchical queries in Oracle](http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm)
358
+ - [Recursive queries in PostgreSQL](http://www.postgresql.org/docs/9.3/static/queries-with.html)
359
+ - [Using Recursive SQL with ActiveRecord trees](http://hashrocket.com/blog/posts/recursive-sql-in-activerecord)
366
360
 
367
361
  ## Contributing
368
362
 
@@ -1,5 +1,3 @@
1
- require 'arel/visitors/depth_first'
2
-
3
1
  module ActiveRecord
4
2
  module HierarchicalQuery
5
3
  module CTE
@@ -18,7 +16,23 @@ module ActiveRecord
18
16
 
19
17
  private
20
18
  def connect_by_columns
21
- @query.join_conditions.grep(Arel::Attributes::Attribute) { |column| column.name.to_s }
19
+ columns = []
20
+ traverse(@query.join_conditions) do |node|
21
+ columns << node.name.to_s if node.is_a?(Arel::Attributes::Attribute)
22
+ end
23
+ columns
24
+ end
25
+
26
+ def traverse(ast, &blck)
27
+ if ast && ast.respond_to?(:left) && ast.left
28
+ traverse(ast.left, &blck)
29
+ end
30
+
31
+ if ast && ast.respond_to?(:right) && ast.right
32
+ traverse(ast.right, &blck)
33
+ end
34
+
35
+ yield ast
22
36
  end
23
37
  end
24
38
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module HierarchicalQuery
3
- VERSION = '1.2.1'
3
+ VERSION = '1.4.0.alpha1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-hierarchical_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei Mikhailov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-15 00:00:00.000000000 Z
12
+ date: 2022-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -18,9 +18,9 @@ dependencies:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '5.0'
21
- - - "<="
21
+ - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '6.0'
23
+ version: '6.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,9 +28,9 @@ dependencies:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '5.0'
31
- - - "<="
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '6.2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: pg
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: '0.21'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '1.2'
43
+ version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,19 +50,19 @@ dependencies:
50
50
  version: '0.21'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '1.2'
53
+ version: '1.3'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: bundler
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.16'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - "~>"
65
+ - - ">="
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.16'
68
68
  - !ruby/object:Gem::Dependency
@@ -85,14 +85,14 @@ dependencies:
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.8'
88
+ version: '3.10'
89
89
  type: :development
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '3.8'
95
+ version: '3.10'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: database_cleaner
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -165,11 +165,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
- - - ">="
168
+ - - ">"
169
169
  - !ruby/object:Gem::Version
170
- version: '0'
170
+ version: 1.3.1
171
171
  requirements: []
172
- rubygems_version: 3.0.6
172
+ rubygems_version: 3.2.22
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Recursively traverse trees using a single SQL query