active_record-union_relation 0.1.1 → 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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +16 -0
- data/.github/workflows/auto-merge.yml +22 -0
- data/.github/workflows/main.yml +66 -18
- data/CHANGELOG.md +9 -1
- data/Gemfile +5 -1
- data/Gemfile.lock +169 -111
- data/README.md +6 -14
- data/Rakefile +14 -5
- data/active_record-union_relation.gemspec +28 -28
- data/gemfiles/mysql/Gemfile +7 -0
- data/gemfiles/mysql/Gemfile.lock +202 -0
- data/gemfiles/postgresql/Gemfile +7 -0
- data/gemfiles/postgresql/Gemfile.lock +202 -0
- data/gemfiles/sqlite/Gemfile +7 -0
- data/gemfiles/sqlite/Gemfile.lock +203 -0
- data/lib/active_record/union_relation/version.rb +1 -1
- data/lib/active_record/union_relation.rb +55 -24
- metadata +30 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0920889c3d3a7bd7ef4cd4e24fde9325418a7d2b108495265af571a3ff3cec88'
|
|
4
|
+
data.tar.gz: f056308e383a312cb440eab986a28d95788ae88ce14ffa1b5cac9799c4fd44b9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4709e79f723b4cf9279f708eaf0a6860ba4b39d3411678ebf1ea7c34923c685af1ae8359004afcdf08178d90f629f355cb5aa98c7b0d1bdabcb5710ba8b28576
|
|
7
|
+
data.tar.gz: 106be365eb3f8d6e528d1617e9a95ede261a15c1603e2d147fd4452538190ce47a11d8f556135251591567fc864975b4f54c8bf9a8ca0d449d51d45dcd04552a
|
data/.github/dependabot.yml
CHANGED
|
@@ -4,3 +4,19 @@ updates:
|
|
|
4
4
|
directory: "/"
|
|
5
5
|
schedule:
|
|
6
6
|
interval: "daily"
|
|
7
|
+
- package-ecosystem: "bundler"
|
|
8
|
+
directory: "/gemfiles/mysql"
|
|
9
|
+
schedule:
|
|
10
|
+
interval: "daily"
|
|
11
|
+
- package-ecosystem: "bundler"
|
|
12
|
+
directory: "/gemfiles/postgresql"
|
|
13
|
+
schedule:
|
|
14
|
+
interval: "daily"
|
|
15
|
+
- package-ecosystem: "bundler"
|
|
16
|
+
directory: "/gemfiles/sqlite"
|
|
17
|
+
schedule:
|
|
18
|
+
interval: "daily"
|
|
19
|
+
- package-ecosystem: "github-actions"
|
|
20
|
+
directory: "/"
|
|
21
|
+
schedule:
|
|
22
|
+
interval: "daily"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Dependabot auto-merge
|
|
2
|
+
on: pull_request
|
|
3
|
+
|
|
4
|
+
permissions:
|
|
5
|
+
contents: write
|
|
6
|
+
pull-requests: write
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
dependabot:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
if: ${{ github.actor == 'dependabot[bot]' }}
|
|
12
|
+
steps:
|
|
13
|
+
- name: Dependabot metadata
|
|
14
|
+
id: metadata
|
|
15
|
+
uses: dependabot/fetch-metadata@v1.6.0
|
|
16
|
+
with:
|
|
17
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
|
18
|
+
- name: Enable auto-merge for Dependabot PRs
|
|
19
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
|
20
|
+
env:
|
|
21
|
+
PR_URL: ${{github.event.pull_request.html_url}}
|
|
22
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
data/.github/workflows/main.yml
CHANGED
|
@@ -1,13 +1,60 @@
|
|
|
1
1
|
name: Main
|
|
2
|
+
|
|
2
3
|
on:
|
|
3
4
|
- push
|
|
4
|
-
-
|
|
5
|
+
- pull_request
|
|
6
|
+
|
|
5
7
|
jobs:
|
|
6
|
-
|
|
7
|
-
name:
|
|
8
|
+
lint:
|
|
9
|
+
name: Lint
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- run: sudo apt-get -yqq install libpq-dev libsqlite3-dev
|
|
13
|
+
- uses: actions/checkout@master
|
|
14
|
+
- uses: ruby/setup-ruby@v1
|
|
15
|
+
with:
|
|
16
|
+
ruby-version: '3.3'
|
|
17
|
+
bundler-cache: true
|
|
18
|
+
- name: Lint
|
|
19
|
+
run: bundle exec rake stree:check
|
|
20
|
+
mysql:
|
|
21
|
+
name: MySQL
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
env:
|
|
24
|
+
BUNDLE_GEMFILE: gemfiles/mysql/Gemfile
|
|
25
|
+
DATABASE_URL: mysql2://root:password@127.0.0.1:3306/test
|
|
26
|
+
RAILS_ENV: test
|
|
27
|
+
services:
|
|
28
|
+
mysql:
|
|
29
|
+
image: mysql:5.7
|
|
30
|
+
env:
|
|
31
|
+
MYSQL_DATABASE: test
|
|
32
|
+
MYSQL_USERNAME: root
|
|
33
|
+
MYSQL_PASSWORD: password
|
|
34
|
+
MYSQL_ROOT_PASSWORD: password
|
|
35
|
+
MYSQL_HOST: 127.0.0.1
|
|
36
|
+
MYSQL_PORT: 3306
|
|
37
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
|
|
38
|
+
ports:
|
|
39
|
+
- 3306:3306
|
|
40
|
+
options: >-
|
|
41
|
+
--health-cmd="mysqladmin ping"
|
|
42
|
+
--health-interval=10s
|
|
43
|
+
--health-timeout=5s
|
|
44
|
+
--health-retries=3
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@master
|
|
47
|
+
- uses: ruby/setup-ruby@v1
|
|
48
|
+
with:
|
|
49
|
+
ruby-version: '3.3'
|
|
50
|
+
bundler-cache: true
|
|
51
|
+
- name: Test
|
|
52
|
+
run: bundle exec rake test
|
|
53
|
+
postgresql:
|
|
54
|
+
name: PostgreSQL
|
|
8
55
|
runs-on: ubuntu-latest
|
|
9
56
|
env:
|
|
10
|
-
|
|
57
|
+
BUNDLE_GEMFILE: gemfiles/postgresql/Gemfile
|
|
11
58
|
DATABASE_URL: postgres://postgres:@localhost:5432/postgres
|
|
12
59
|
RAILS_ENV: test
|
|
13
60
|
services:
|
|
@@ -25,22 +72,23 @@ jobs:
|
|
|
25
72
|
- uses: actions/checkout@master
|
|
26
73
|
- uses: ruby/setup-ruby@v1
|
|
27
74
|
with:
|
|
28
|
-
ruby-version: 3.
|
|
75
|
+
ruby-version: '3.3'
|
|
29
76
|
bundler-cache: true
|
|
30
77
|
- name: Test
|
|
31
|
-
run:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
name: AutoMerge
|
|
35
|
-
needs: ci
|
|
78
|
+
run: bundle exec rake test
|
|
79
|
+
sqlite:
|
|
80
|
+
name: SQLite
|
|
36
81
|
runs-on: ubuntu-latest
|
|
37
|
-
|
|
82
|
+
env:
|
|
83
|
+
BUNDLE_GEMFILE: gemfiles/sqlite/Gemfile
|
|
84
|
+
DATABASE_URL: "sqlite3::memory:"
|
|
85
|
+
RAILS_ENV: test
|
|
38
86
|
steps:
|
|
39
|
-
-
|
|
87
|
+
- run: sudo apt-get -yqq install libsqlite3-dev
|
|
88
|
+
- uses: actions/checkout@master
|
|
89
|
+
- uses: ruby/setup-ruby@v1
|
|
40
90
|
with:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
pull_number: context.payload.pull_request.number
|
|
46
|
-
})
|
|
91
|
+
ruby-version: '3.3'
|
|
92
|
+
bundler-cache: true
|
|
93
|
+
- name: Test
|
|
94
|
+
run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.2.0] - 2024-02-09
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Support for sqlite.
|
|
14
|
+
- Support for scoped column names.
|
|
15
|
+
|
|
9
16
|
## [0.1.1] - 2021-11-17
|
|
10
17
|
|
|
11
18
|
### Changed
|
|
@@ -18,6 +25,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
|
18
25
|
|
|
19
26
|
- 🎉 Initial release. 🎉
|
|
20
27
|
|
|
21
|
-
[unreleased]: https://github.com/kddnewton/active_record-union_relation/compare/v0.
|
|
28
|
+
[unreleased]: https://github.com/kddnewton/active_record-union_relation/compare/v0.2.0...HEAD
|
|
29
|
+
[0.2.0]: https://github.com/kddnewton/active_record-union_relation/compare/v0.1.1...v0.2.0
|
|
22
30
|
[0.1.1]: https://github.com/kddnewton/active_record-union_relation/compare/v0.1.0...v0.1.1
|
|
23
31
|
[0.1.0]: https://github.com/kddnewton/active_record-union_relation/compare/a71bb8...v0.1.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,149 +1,207 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
active_record-union_relation (0.
|
|
4
|
+
active_record-union_relation (0.2.0)
|
|
5
5
|
activerecord (>= 6)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actioncable (
|
|
11
|
-
actionpack (=
|
|
12
|
-
activesupport (=
|
|
10
|
+
actioncable (7.1.3)
|
|
11
|
+
actionpack (= 7.1.3)
|
|
12
|
+
activesupport (= 7.1.3)
|
|
13
13
|
nio4r (~> 2.0)
|
|
14
14
|
websocket-driver (>= 0.6.1)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
zeitwerk (~> 2.6)
|
|
16
|
+
actionmailbox (7.1.3)
|
|
17
|
+
actionpack (= 7.1.3)
|
|
18
|
+
activejob (= 7.1.3)
|
|
19
|
+
activerecord (= 7.1.3)
|
|
20
|
+
activestorage (= 7.1.3)
|
|
21
|
+
activesupport (= 7.1.3)
|
|
21
22
|
mail (>= 2.7.1)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
net-imap
|
|
24
|
+
net-pop
|
|
25
|
+
net-smtp
|
|
26
|
+
actionmailer (7.1.3)
|
|
27
|
+
actionpack (= 7.1.3)
|
|
28
|
+
actionview (= 7.1.3)
|
|
29
|
+
activejob (= 7.1.3)
|
|
30
|
+
activesupport (= 7.1.3)
|
|
27
31
|
mail (~> 2.5, >= 2.5.4)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
net-imap
|
|
33
|
+
net-pop
|
|
34
|
+
net-smtp
|
|
35
|
+
rails-dom-testing (~> 2.2)
|
|
36
|
+
actionpack (7.1.3)
|
|
37
|
+
actionview (= 7.1.3)
|
|
38
|
+
activesupport (= 7.1.3)
|
|
39
|
+
nokogiri (>= 1.8.5)
|
|
40
|
+
racc
|
|
41
|
+
rack (>= 2.2.4)
|
|
42
|
+
rack-session (>= 1.0.1)
|
|
33
43
|
rack-test (>= 0.6.3)
|
|
34
|
-
rails-dom-testing (~> 2.
|
|
35
|
-
rails-html-sanitizer (~> 1.
|
|
36
|
-
actiontext (
|
|
37
|
-
actionpack (=
|
|
38
|
-
activerecord (=
|
|
39
|
-
activestorage (=
|
|
40
|
-
activesupport (=
|
|
44
|
+
rails-dom-testing (~> 2.2)
|
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
|
46
|
+
actiontext (7.1.3)
|
|
47
|
+
actionpack (= 7.1.3)
|
|
48
|
+
activerecord (= 7.1.3)
|
|
49
|
+
activestorage (= 7.1.3)
|
|
50
|
+
activesupport (= 7.1.3)
|
|
51
|
+
globalid (>= 0.6.0)
|
|
41
52
|
nokogiri (>= 1.8.5)
|
|
42
|
-
actionview (
|
|
43
|
-
activesupport (=
|
|
53
|
+
actionview (7.1.3)
|
|
54
|
+
activesupport (= 7.1.3)
|
|
44
55
|
builder (~> 3.1)
|
|
45
|
-
erubi (~> 1.
|
|
46
|
-
rails-dom-testing (~> 2.
|
|
47
|
-
rails-html-sanitizer (~> 1.
|
|
48
|
-
activejob (
|
|
49
|
-
activesupport (=
|
|
56
|
+
erubi (~> 1.11)
|
|
57
|
+
rails-dom-testing (~> 2.2)
|
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
|
59
|
+
activejob (7.1.3)
|
|
60
|
+
activesupport (= 7.1.3)
|
|
50
61
|
globalid (>= 0.3.6)
|
|
51
|
-
activemodel (
|
|
52
|
-
activesupport (=
|
|
53
|
-
activerecord (
|
|
54
|
-
activemodel (=
|
|
55
|
-
activesupport (=
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
activesupport (
|
|
62
|
+
activemodel (7.1.3)
|
|
63
|
+
activesupport (= 7.1.3)
|
|
64
|
+
activerecord (7.1.3)
|
|
65
|
+
activemodel (= 7.1.3)
|
|
66
|
+
activesupport (= 7.1.3)
|
|
67
|
+
timeout (>= 0.4.0)
|
|
68
|
+
activestorage (7.1.3)
|
|
69
|
+
actionpack (= 7.1.3)
|
|
70
|
+
activejob (= 7.1.3)
|
|
71
|
+
activerecord (= 7.1.3)
|
|
72
|
+
activesupport (= 7.1.3)
|
|
73
|
+
marcel (~> 1.0)
|
|
74
|
+
activesupport (7.1.3)
|
|
75
|
+
base64
|
|
76
|
+
bigdecimal
|
|
64
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
78
|
+
connection_pool (>= 2.2.5)
|
|
79
|
+
drb
|
|
65
80
|
i18n (>= 1.6, < 2)
|
|
66
81
|
minitest (>= 5.1)
|
|
82
|
+
mutex_m
|
|
67
83
|
tzinfo (~> 2.0)
|
|
68
|
-
|
|
84
|
+
base64 (0.2.0)
|
|
85
|
+
bigdecimal (3.1.6)
|
|
69
86
|
builder (3.2.4)
|
|
70
|
-
concurrent-ruby (1.
|
|
87
|
+
concurrent-ruby (1.2.3)
|
|
88
|
+
connection_pool (2.4.1)
|
|
71
89
|
crass (1.0.6)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
date (3.3.4)
|
|
91
|
+
drb (2.2.0)
|
|
92
|
+
ruby2_keywords
|
|
93
|
+
erubi (1.12.0)
|
|
94
|
+
globalid (1.2.1)
|
|
95
|
+
activesupport (>= 6.1)
|
|
96
|
+
i18n (1.14.1)
|
|
76
97
|
concurrent-ruby (~> 1.0)
|
|
77
|
-
|
|
98
|
+
io-console (0.7.2)
|
|
99
|
+
irb (1.11.2)
|
|
100
|
+
rdoc
|
|
101
|
+
reline (>= 0.4.2)
|
|
102
|
+
loofah (2.22.0)
|
|
78
103
|
crass (~> 1.0.2)
|
|
79
|
-
nokogiri (>= 1.
|
|
80
|
-
mail (2.
|
|
104
|
+
nokogiri (>= 1.12.0)
|
|
105
|
+
mail (2.8.1)
|
|
81
106
|
mini_mime (>= 0.1.1)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
107
|
+
net-imap
|
|
108
|
+
net-pop
|
|
109
|
+
net-smtp
|
|
110
|
+
marcel (1.0.2)
|
|
111
|
+
mini_mime (1.1.5)
|
|
112
|
+
minitest (5.22.2)
|
|
113
|
+
mutex_m (0.2.0)
|
|
114
|
+
mysql2 (0.5.6)
|
|
115
|
+
net-imap (0.4.10)
|
|
116
|
+
date
|
|
117
|
+
net-protocol
|
|
118
|
+
net-pop (0.1.2)
|
|
119
|
+
net-protocol
|
|
120
|
+
net-protocol (0.2.2)
|
|
121
|
+
timeout
|
|
122
|
+
net-smtp (0.4.0.1)
|
|
123
|
+
net-protocol
|
|
124
|
+
nio4r (2.7.0)
|
|
125
|
+
nokogiri (1.16.2-arm64-darwin)
|
|
126
|
+
racc (~> 1.4)
|
|
127
|
+
nokogiri (1.16.2-x86_64-linux)
|
|
90
128
|
racc (~> 1.4)
|
|
91
|
-
pg (1.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
pg (1.5.4)
|
|
130
|
+
prettier_print (1.2.1)
|
|
131
|
+
psych (5.1.2)
|
|
132
|
+
stringio
|
|
133
|
+
racc (1.7.3)
|
|
134
|
+
rack (3.0.9)
|
|
135
|
+
rack-session (2.0.0)
|
|
136
|
+
rack (>= 3.0.0)
|
|
137
|
+
rack-test (2.1.0)
|
|
138
|
+
rack (>= 1.3)
|
|
139
|
+
rackup (2.1.0)
|
|
140
|
+
rack (>= 3)
|
|
141
|
+
webrick (~> 1.8)
|
|
142
|
+
rails (7.1.3)
|
|
143
|
+
actioncable (= 7.1.3)
|
|
144
|
+
actionmailbox (= 7.1.3)
|
|
145
|
+
actionmailer (= 7.1.3)
|
|
146
|
+
actionpack (= 7.1.3)
|
|
147
|
+
actiontext (= 7.1.3)
|
|
148
|
+
actionview (= 7.1.3)
|
|
149
|
+
activejob (= 7.1.3)
|
|
150
|
+
activemodel (= 7.1.3)
|
|
151
|
+
activerecord (= 7.1.3)
|
|
152
|
+
activestorage (= 7.1.3)
|
|
153
|
+
activesupport (= 7.1.3)
|
|
108
154
|
bundler (>= 1.15.0)
|
|
109
|
-
railties (=
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
155
|
+
railties (= 7.1.3)
|
|
156
|
+
rails-dom-testing (2.2.0)
|
|
157
|
+
activesupport (>= 5.0.0)
|
|
158
|
+
minitest
|
|
113
159
|
nokogiri (>= 1.6)
|
|
114
|
-
rails-html-sanitizer (1.
|
|
115
|
-
loofah (~> 2.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
160
|
+
rails-html-sanitizer (1.6.0)
|
|
161
|
+
loofah (~> 2.21)
|
|
162
|
+
nokogiri (~> 1.14)
|
|
163
|
+
railties (7.1.3)
|
|
164
|
+
actionpack (= 7.1.3)
|
|
165
|
+
activesupport (= 7.1.3)
|
|
166
|
+
irb
|
|
167
|
+
rackup (>= 1.0.0)
|
|
168
|
+
rake (>= 12.2)
|
|
169
|
+
thor (~> 1.0, >= 1.2.2)
|
|
170
|
+
zeitwerk (~> 2.6)
|
|
171
|
+
rake (13.1.0)
|
|
172
|
+
rdoc (6.6.2)
|
|
173
|
+
psych (>= 4.0.0)
|
|
174
|
+
reline (0.4.2)
|
|
175
|
+
io-console (~> 0.5)
|
|
176
|
+
ruby2_keywords (0.0.5)
|
|
177
|
+
sqlite3 (1.7.2-arm64-darwin)
|
|
178
|
+
sqlite3 (1.7.2-x86_64-linux)
|
|
179
|
+
stringio (3.1.0)
|
|
180
|
+
syntax_tree (6.2.0)
|
|
181
|
+
prettier_print (>= 1.2.0)
|
|
182
|
+
thor (1.3.0)
|
|
183
|
+
timeout (0.4.1)
|
|
184
|
+
tzinfo (2.0.6)
|
|
132
185
|
concurrent-ruby (~> 1.0)
|
|
133
|
-
|
|
186
|
+
webrick (1.8.1)
|
|
187
|
+
websocket-driver (0.7.6)
|
|
134
188
|
websocket-extensions (>= 0.1.0)
|
|
135
189
|
websocket-extensions (0.1.5)
|
|
136
|
-
zeitwerk (2.
|
|
190
|
+
zeitwerk (2.6.13)
|
|
137
191
|
|
|
138
192
|
PLATFORMS
|
|
139
|
-
|
|
193
|
+
arm64-darwin-22
|
|
194
|
+
x86_64-linux
|
|
140
195
|
|
|
141
196
|
DEPENDENCIES
|
|
142
197
|
active_record-union_relation!
|
|
143
|
-
minitest
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
198
|
+
minitest
|
|
199
|
+
mysql2
|
|
200
|
+
pg
|
|
201
|
+
rails
|
|
202
|
+
rake
|
|
203
|
+
sqlite3
|
|
204
|
+
syntax_tree
|
|
147
205
|
|
|
148
206
|
BUNDLED WITH
|
|
149
|
-
2.
|
|
207
|
+
2.4.1
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# ActiveRecord::UnionRelation
|
|
2
2
|
|
|
3
3
|
[](https://github.com/kddnewton/active_record-union_relation/actions)
|
|
4
|
+
[](https://rubygems.org/gems/active_record-union_relation)
|
|
4
5
|
|
|
5
6
|
There are times when you want to use SQL's [UNION](https://www.w3schools.com/sql/sql_union.asp) operator to pull rows from multiple relations, but you still want to maintain the query-builder interface of ActiveRecord. This gem allows you to do that with minimal syntax.
|
|
6
7
|
|
|
@@ -9,7 +10,7 @@ There are times when you want to use SQL's [UNION](https://www.w3schools.com/sql
|
|
|
9
10
|
Add this line to your application's Gemfile:
|
|
10
11
|
|
|
11
12
|
```ruby
|
|
12
|
-
gem
|
|
13
|
+
gem "active_record-union_relation"
|
|
13
14
|
```
|
|
14
15
|
|
|
15
16
|
And then execute:
|
|
@@ -46,7 +47,7 @@ Now, let's pull all of the records matching a specific term. For `Post`, we'll p
|
|
|
46
47
|
```ruby
|
|
47
48
|
# Let's get a local variable that we'll use to reference within each of our
|
|
48
49
|
# subqueries. Presumably this would come from some kind of user input.
|
|
49
|
-
term =
|
|
50
|
+
term = "foo"
|
|
50
51
|
|
|
51
52
|
# First, we call ActiveRecord::union. The arguments are the names of the columns
|
|
52
53
|
# that will be aliased from each source relation. It also accepts a block that
|
|
@@ -58,7 +59,7 @@ relation =
|
|
|
58
59
|
# just for this one table. That can include any kind of
|
|
59
60
|
# joins/conditions/orders etc. that it needs to. In this case we'll need
|
|
60
61
|
# published: true and a matching query.
|
|
61
|
-
posts = Post.where(published: true).where(
|
|
62
|
+
posts = Post.where(published: true).where("title LIKE ?", "%#{term}%")
|
|
62
63
|
|
|
63
64
|
# Next, we'll add that posts relation as a subquery into the union. The
|
|
64
65
|
# number of arguments here must directly align with the number of arguments
|
|
@@ -73,12 +74,12 @@ relation =
|
|
|
73
74
|
# explicitly pulling post_id, we'll actually be able to call .post on the
|
|
74
75
|
# comment records that get pulled since we alias them back when we
|
|
75
76
|
# instantiate the objects.
|
|
76
|
-
comments = Comment.where(
|
|
77
|
+
comments = Comment.where("body LIKE ?", "%#{term}%")
|
|
77
78
|
union.add comments, :id, :post_id, :body
|
|
78
79
|
|
|
79
80
|
# Finally, we'll pull the tag records that we want and add them into the
|
|
80
81
|
# overall union as well.
|
|
81
|
-
tags = Tag.where(
|
|
82
|
+
tags = Tag.where("name LIKE ?", "%#{term}%")
|
|
82
83
|
union.add tags, :id, nil, :name
|
|
83
84
|
end
|
|
84
85
|
|
|
@@ -114,15 +115,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
|
114
115
|
|
|
115
116
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
116
117
|
|
|
117
|
-
To check types using `rbs`, you can run:
|
|
118
|
-
|
|
119
|
-
```sh
|
|
120
|
-
RBS_TEST_TARGET='ActiveRecord::UnionRelation::*' \
|
|
121
|
-
ruby -rrbs/test/setup \
|
|
122
|
-
-Itest -Isig/active_record/union_relation.rbs \
|
|
123
|
-
test/active_record/union_relation_test.rb
|
|
124
|
-
```
|
|
125
|
-
|
|
126
118
|
## Contributing
|
|
127
119
|
|
|
128
120
|
Bug reports and pull requests are welcome on GitHub at https://github.com/kddnewton/active_record-union_relation.
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "bundler/gem_tasks"
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
require "syntax_tree/rake_tasks"
|
|
5
6
|
|
|
6
7
|
Rake::TestTask.new(:test) do |t|
|
|
7
|
-
t.libs <<
|
|
8
|
-
t.libs <<
|
|
9
|
-
t.test_files = FileList[
|
|
8
|
+
t.libs << "test"
|
|
9
|
+
t.libs << "lib"
|
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
10
11
|
end
|
|
11
12
|
|
|
12
13
|
task default: :test
|
|
14
|
+
|
|
15
|
+
configure = ->(task) do
|
|
16
|
+
task.source_files =
|
|
17
|
+
FileList[%w[Gemfile Rakefile *.gemspec lib/**/*.rb test/**/*.rb]]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
SyntaxTree::Rake::CheckTask.new(&configure)
|
|
21
|
+
SyntaxTree::Rake::WriteTask.new(&configure)
|