activerecord-setops 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +14 -13
- data/README.md +41 -1
- data/activerecord-setops.gemspec +3 -2
- data/lib/active_record/setops.rb +3 -4
- data/lib/active_record/setops/version.rb +1 -1
- data/lib/activerecord-setops.rb +1 -0
- metadata +39 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19f77a7a5a20214036dc0394e28556788dcbbf95a9c78f8b502fe52fb551ec66
|
4
|
+
data.tar.gz: 9393dd62ceb050cd2605b9b112b7d3cd442e677398fb3ca1d13e7ec8cb836fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f52b0afedfca8afa3fe948c831fb0ab6db2e31d37618268ee0246e8248f903fa8e83f70ccc7d785603011d0a7bc836a55fa6badbd7aa29d6eb24834f3647f02
|
7
|
+
data.tar.gz: 8a8e060c36ab59c0f5b50dabe04d7071a8251fb0835ddecb8aa9682211767c5698000ccd76397f98525fa81217afbcabaa0edc7cad08645bc4a646407ccec420
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activerecord-setops (0.1.
|
4
|
+
activerecord-setops (0.1.7)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (5.2.4.
|
10
|
-
activesupport (= 5.2.4.
|
11
|
-
activerecord (5.2.4.
|
12
|
-
activemodel (= 5.2.4.
|
13
|
-
activesupport (= 5.2.4.
|
9
|
+
activemodel (5.2.4.3)
|
10
|
+
activesupport (= 5.2.4.3)
|
11
|
+
activerecord (5.2.4.3)
|
12
|
+
activemodel (= 5.2.4.3)
|
13
|
+
activesupport (= 5.2.4.3)
|
14
14
|
arel (>= 9.0)
|
15
|
-
activesupport (5.2.4.
|
15
|
+
activesupport (5.2.4.3)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 0.7, < 2)
|
18
18
|
minitest (~> 5.1)
|
19
19
|
tzinfo (~> 1.1)
|
20
20
|
arel (9.0.0)
|
21
|
-
concurrent-ruby (1.1.
|
21
|
+
concurrent-ruby (1.1.6)
|
22
22
|
contracts (0.16.0)
|
23
23
|
contracts-gen (0.1.1)
|
24
24
|
contracts (~> 0.16.0)
|
@@ -32,8 +32,8 @@ GEM
|
|
32
32
|
regexp-examples (~> 1.5.0)
|
33
33
|
i18n (1.8.2)
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
|
-
minitest (5.14.
|
36
|
-
rake (
|
35
|
+
minitest (5.14.1)
|
36
|
+
rake (13.0.1)
|
37
37
|
regexp-examples (1.5.1)
|
38
38
|
rspec (3.9.0)
|
39
39
|
rspec-core (~> 3.9.0)
|
@@ -50,19 +50,20 @@ GEM
|
|
50
50
|
rspec-support (3.9.2)
|
51
51
|
sqlite3 (1.4.2)
|
52
52
|
thread_safe (0.3.6)
|
53
|
-
tzinfo (1.2.
|
53
|
+
tzinfo (1.2.7)
|
54
54
|
thread_safe (~> 0.1)
|
55
55
|
|
56
56
|
PLATFORMS
|
57
57
|
ruby
|
58
58
|
|
59
59
|
DEPENDENCIES
|
60
|
-
activerecord (
|
60
|
+
activerecord (>= 5.2.4.3, < 6)
|
61
61
|
activerecord-setops!
|
62
|
+
activesupport (>= 5.2.4.3, < 6)
|
62
63
|
bundler (~> 1.17)
|
63
64
|
contracts-gen (~> 0.1.1)
|
64
65
|
gen-test (~> 0.1.1)
|
65
|
-
rake (~>
|
66
|
+
rake (~> 13.0)
|
66
67
|
rspec (~> 3.0)
|
67
68
|
sqlite3 (~> 1.4.2)
|
68
69
|
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
![Ruby](https://github.com/delonnewman/activerecord-setops/workflows/Ruby/badge.svg)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/activerecord-setops.svg)](https://badge.fury.io/rb/activerecord-setops)
|
2
3
|
|
3
4
|
# ActiveRecord::Setops
|
4
5
|
|
@@ -16,7 +17,7 @@ class Employee < ActiveRecord::Base; end
|
|
16
17
|
|
17
18
|
# Why?
|
18
19
|
|
19
|
-
Joins can be difficult to reason about in Arel (
|
20
|
+
Joins can be difficult to reason about in Arel (and SQL for that matter). Many joins can be replaced
|
20
21
|
with set operations which are much simpler beasts, may offer performance gains, and have consistent
|
21
22
|
mathematical properties. But these operations while present in Arel are missing in ActiveRecord. This
|
22
23
|
module attempts to correct this lack.
|
@@ -37,7 +38,46 @@ Or install it yourself as:
|
|
37
38
|
|
38
39
|
$ gem install activerecord-setops
|
39
40
|
|
41
|
+
# Non-Installation
|
42
|
+
|
43
|
+
If you'd like the functionality, but would prefer to avoid yet another dependency, please fill free to paste the following code into your nearest lib directory, I'm certain it's not perfect but it has been [tested](spec/active_record/setops_spec.rb) with Rails 5, and is being used in production.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
module ActiveRecord
|
47
|
+
class Relation
|
48
|
+
# Performs a set theoretic union works like `Array#+` but puts the load on the database
|
49
|
+
# and allows you to chain more relation operations.
|
50
|
+
def union(other)
|
51
|
+
binary_operation(Arel::Nodes::Union, other)
|
52
|
+
end
|
53
|
+
alias | union
|
54
|
+
alias + union
|
55
|
+
|
56
|
+
def union_all(other)
|
57
|
+
binary_operation(Arel::Nodes::UnionAll, other)
|
58
|
+
end
|
59
|
+
|
60
|
+
def intersect(other)
|
61
|
+
binary_operation(Arel::Nodes::Intersect, other)
|
62
|
+
end
|
63
|
+
alias & intersect
|
64
|
+
|
65
|
+
def difference(other)
|
66
|
+
binary_operation(Arel::Nodes::Except, other)
|
67
|
+
end
|
68
|
+
alias - difference
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def binary_operation(op_class, other)
|
73
|
+
@klass.unscoped.from(Arel::Nodes::TableAlias.new(op_class.new(self.arel.ast, other.arel.ast), @klass.arel_table.name))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
40
79
|
# See Also
|
41
80
|
|
42
81
|
- [Sequel](http://sequel.jeremyevans.net)
|
43
82
|
- [SQL Set Operations](https://en.wikipedia.org/wiki/Set_operations_(SQL))
|
83
|
+
- [active_record_union](https://github.com/brianhempel/active_record_union)
|
data/activerecord-setops.gemspec
CHANGED
@@ -37,10 +37,11 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.require_paths = ["lib"]
|
38
38
|
|
39
39
|
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
-
spec.add_development_dependency "rake", "~>
|
40
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
41
41
|
spec.add_development_dependency "rspec", "~> 3.0"
|
42
42
|
spec.add_development_dependency "gen-test", "~> 0.1.1"
|
43
43
|
spec.add_development_dependency "contracts-gen", "~> 0.1.1"
|
44
|
-
spec.add_development_dependency "activerecord", "
|
44
|
+
spec.add_development_dependency "activerecord", [">= 5.2.4.3", "< 6"]
|
45
|
+
spec.add_development_dependency "activesupport", [">= 5.2.4.3", "< 6"]
|
45
46
|
spec.add_development_dependency "sqlite3", "~> 1.4.2"
|
46
47
|
end
|
data/lib/active_record/setops.rb
CHANGED
@@ -8,22 +8,21 @@ module ActiveRecord
|
|
8
8
|
binary_operation(Arel::Nodes::Union, other)
|
9
9
|
end
|
10
10
|
alias | union
|
11
|
-
alias + union
|
12
11
|
|
13
12
|
def union_all(other)
|
14
13
|
binary_operation(Arel::Nodes::UnionAll, other)
|
15
14
|
end
|
15
|
+
alias + union_all
|
16
16
|
|
17
17
|
def intersect(other)
|
18
18
|
binary_operation(Arel::Nodes::Intersect, other)
|
19
19
|
end
|
20
20
|
alias & intersect
|
21
21
|
|
22
|
-
def
|
22
|
+
def difference(other)
|
23
23
|
binary_operation(Arel::Nodes::Except, other)
|
24
24
|
end
|
25
|
-
alias difference
|
26
|
-
alias - except
|
25
|
+
alias - difference
|
27
26
|
|
28
27
|
private
|
29
28
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'active_record/setops'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-setops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delon Newman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,16 +84,42 @@ dependencies:
|
|
84
84
|
name: activerecord
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.2.4.3
|
90
|
+
- - "<"
|
88
91
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
92
|
+
version: '6'
|
90
93
|
type: :development
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
|
-
- - "
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 5.2.4.3
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '6'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: activesupport
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 5.2.4.3
|
110
|
+
- - "<"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '6'
|
113
|
+
type: :development
|
114
|
+
prerelease: false
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 5.2.4.3
|
120
|
+
- - "<"
|
95
121
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
122
|
+
version: '6'
|
97
123
|
- !ruby/object:Gem::Dependency
|
98
124
|
name: sqlite3
|
99
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +144,7 @@ files:
|
|
118
144
|
- ".github/workflows/ruby.yml"
|
119
145
|
- ".gitignore"
|
120
146
|
- ".rspec"
|
147
|
+
- CHANGELOG.md
|
121
148
|
- Gemfile
|
122
149
|
- Gemfile.lock
|
123
150
|
- LICENSE.txt
|
@@ -126,6 +153,7 @@ files:
|
|
126
153
|
- activerecord-setops.gemspec
|
127
154
|
- lib/active_record/setops.rb
|
128
155
|
- lib/active_record/setops/version.rb
|
156
|
+
- lib/activerecord-setops.rb
|
129
157
|
homepage: https://github.com/delonnewman/activerecord-setops#readme
|
130
158
|
licenses:
|
131
159
|
- MIT
|
@@ -135,7 +163,7 @@ metadata:
|
|
135
163
|
source_code_uri: https://github.com/delonnewman/activerecord-setops
|
136
164
|
changelog_uri: https://github.com/delonnewman/activerecord-setops#changelog
|
137
165
|
documentation_uri: https://www.rubydoc.info/gems/activerecord-setops
|
138
|
-
post_install_message:
|
166
|
+
post_install_message:
|
139
167
|
rdoc_options: []
|
140
168
|
require_paths:
|
141
169
|
- lib
|
@@ -151,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
179
|
version: '0'
|
152
180
|
requirements: []
|
153
181
|
rubygems_version: 3.0.6
|
154
|
-
signing_key:
|
182
|
+
signing_key:
|
155
183
|
specification_version: 4
|
156
184
|
summary: Set operations for ActiveRecord
|
157
185
|
test_files: []
|