activerecord-cte 0.1.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test-with-mysql.yml +10 -1
- data/.github/workflows/test-with-postgresql.yml +12 -2
- data/.github/workflows/test-with-sqlite.yml +12 -1
- data/.ruby-version +1 -1
- data/Dockerfile +1 -1
- data/Gemfile +1 -1
- data/README.md +3 -1
- data/bin/test +4 -12
- data/lib/activerecord/cte/core_ext.rb +19 -4
- data/lib/activerecord/cte/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fec64d2dc3623acd9cfb623957035c94ce160ac7f1f5bc8df2777d37e8e496b6
|
4
|
+
data.tar.gz: 12d66f36eb856b43a5e23568234884b81db258a67bbed86417e2f28d90449dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28a0be826ae1b0914f8fa4b9e7dd7d9f0221b67b453abfa9f680f943453f12a9436d756378059aade81e4341e352598309dc799441e063d8215c846a00df6ec0
|
7
|
+
data.tar.gz: 78839e99683a7ee08bae702361010986678e1f8a8eaa95e2508edf75188d359a6b3d3295630e4d2a7fb367214dc15d17df69c14a1b8d0d3970f2a5d3a35d49e7
|
@@ -6,7 +6,15 @@ jobs:
|
|
6
6
|
strategy:
|
7
7
|
fail-fast: false
|
8
8
|
matrix:
|
9
|
-
active_record: [6.1.
|
9
|
+
active_record: [6.1.7.2, 6.0.6, 5.2.8.1]
|
10
|
+
ruby: [2.6, 2.7, '3.0', 3.1, 3.2]
|
11
|
+
exclude:
|
12
|
+
- active_record: 5.2.8.1
|
13
|
+
ruby: '3.0'
|
14
|
+
- active_record: 5.2.8.1
|
15
|
+
ruby: 3.1
|
16
|
+
- active_record: 5.2.8.1
|
17
|
+
ruby: 3.2
|
10
18
|
env:
|
11
19
|
ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
|
12
20
|
DATABASE_ADAPTER: mysql
|
@@ -20,6 +28,7 @@ jobs:
|
|
20
28
|
- name: Set up Ruby
|
21
29
|
uses: ruby/setup-ruby@v1
|
22
30
|
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
23
32
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
24
33
|
- name: Run tests
|
25
34
|
run: bundle exec rake test
|
@@ -3,11 +3,19 @@ on: [pull_request]
|
|
3
3
|
jobs:
|
4
4
|
Test-With-PostgreSQL:
|
5
5
|
runs-on: ubuntu-latest
|
6
|
-
container: ruby
|
6
|
+
container: ruby:${{ matrix.ruby }}
|
7
7
|
strategy:
|
8
8
|
fail-fast: false
|
9
9
|
matrix:
|
10
|
-
active_record: [6.1.
|
10
|
+
active_record: [6.1.7.2, 6.0.6, 5.2.8.1]
|
11
|
+
ruby: [2.6, 2.7, '3.0', 3.1, 3.2]
|
12
|
+
exclude:
|
13
|
+
- active_record: 5.2.8.1
|
14
|
+
ruby: '3.0'
|
15
|
+
- active_record: 5.2.8.1
|
16
|
+
ruby: 3.1
|
17
|
+
- active_record: 5.2.8.1
|
18
|
+
ruby: 3.2
|
11
19
|
env:
|
12
20
|
ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
|
13
21
|
DATABASE_ADAPTER: postgresql
|
@@ -28,6 +36,8 @@ jobs:
|
|
28
36
|
steps:
|
29
37
|
- name: Check out repository code
|
30
38
|
uses: actions/checkout@v2
|
39
|
+
- name: Update bundler
|
40
|
+
run: gem update bundler # Use the latest bundler
|
31
41
|
- name: Bundle dependencies
|
32
42
|
run: bundle install
|
33
43
|
- name: Run tests
|
@@ -6,7 +6,17 @@ jobs:
|
|
6
6
|
strategy:
|
7
7
|
fail-fast: false
|
8
8
|
matrix:
|
9
|
-
active_record: [6.1.
|
9
|
+
active_record: [6.1.7.2, 6.0.6, 5.2.8.1]
|
10
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
11
|
+
ruby: [2.6, 2.7, '3.0', 3.1, 3.2]
|
12
|
+
exclude:
|
13
|
+
- active_record: 5.2.8.1
|
14
|
+
ruby: '3.0'
|
15
|
+
- active_record: 5.2.8.1
|
16
|
+
ruby: 3.1
|
17
|
+
- active_record: 5.2.8.1
|
18
|
+
ruby: 3.2
|
19
|
+
|
10
20
|
env:
|
11
21
|
ACTIVE_RECORD_VERSION: ${{ matrix.active_record }}
|
12
22
|
DATABASE_ADAPTER: sqlite3
|
@@ -17,6 +27,7 @@ jobs:
|
|
17
27
|
- name: Set up Ruby
|
18
28
|
uses: ruby/setup-ruby@v1
|
19
29
|
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
20
31
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
21
32
|
- name: Run tests
|
22
33
|
run: bundle exec rake test
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.1.2
|
data/Dockerfile
CHANGED
data/Gemfile
CHANGED
@@ -5,7 +5,7 @@ source "https://rubygems.org"
|
|
5
5
|
# Specify your gem's dependencies in activerecord-cte.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
ACTIVE_RECORD_VERSION = ENV.fetch("ACTIVE_RECORD_VERSION", "6.
|
8
|
+
ACTIVE_RECORD_VERSION = ENV.fetch("ACTIVE_RECORD_VERSION", "6.1.7.2")
|
9
9
|
|
10
10
|
gem "activerecord", ACTIVE_RECORD_VERSION
|
11
11
|
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
![PostgreSQL](https://github.com/vlado/activerecord-cte/actions/workflows/test-with-postgresql.yml/badge.svg)
|
6
6
|
![SQLite](https://github.com/vlado/activerecord-cte/actions/workflows/test-with-sqlite.yml/badge.svg)
|
7
7
|
|
8
|
-
Adds Common Table Expression support to ActiveRecord (Rails).
|
8
|
+
Adds [Common Table Expression](https://en.wikipedia.org/wiki/Hierarchical_and_recursive_queries_in_SQL#Common_table_expression) support to ActiveRecord (Rails).
|
9
9
|
|
10
10
|
It adds `.with` query method and makes it super easy to build and chain complex CTE queries. Let's explain it using simple example.
|
11
11
|
|
@@ -27,6 +27,8 @@ WITH posts_with_comments AS (
|
|
27
27
|
SELECT * FROM posts
|
28
28
|
```
|
29
29
|
|
30
|
+
**Please note that this creates the expressions but is not using them yet. See [Taking it further](#taking-it-further) for more info.**
|
31
|
+
|
30
32
|
Without this gem you would need to use `Arel` directly.
|
31
33
|
|
32
34
|
```ruby
|
data/bin/test
CHANGED
@@ -4,16 +4,8 @@
|
|
4
4
|
require "English"
|
5
5
|
require "yaml"
|
6
6
|
|
7
|
-
active_record_versions = []
|
8
|
-
database_adapters = []
|
9
|
-
|
10
|
-
# Extract ActiveRecord versions and database adapters from CI workflows
|
11
|
-
Dir[".github/workflows/test-**.yml"].each do |path|
|
12
|
-
yml = YAML.load_file(path)
|
13
|
-
job = yml["jobs"].values.first
|
14
|
-
active_record_versions << job["strategy"]["matrix"]["active_record"]
|
15
|
-
database_adapters << job["env"]["DATABASE_ADAPTER"]
|
16
|
-
end
|
7
|
+
active_record_versions = %w[6.1.7.2 6.0.6]
|
8
|
+
database_adapters = %w[mysql postgresql sqlite3]
|
17
9
|
|
18
10
|
class Matrix
|
19
11
|
def initialize(active_record_versions, database_adapters)
|
@@ -28,7 +20,7 @@ class Matrix
|
|
28
20
|
run_with_active_record_version(ar_version)
|
29
21
|
end
|
30
22
|
puts "----> Reverting back to original ActiveRecord version (#{original_ar_version})"
|
31
|
-
cmd("ACTIVE_RECORD_VERSION=#{original_ar_version} bundle update
|
23
|
+
cmd("ACTIVE_RECORD_VERSION=#{original_ar_version} bundle update")
|
32
24
|
|
33
25
|
exit(@exit_status_code) unless @exit_status_code.zero?
|
34
26
|
end
|
@@ -42,7 +34,7 @@ class Matrix
|
|
42
34
|
|
43
35
|
def run_with_active_record_version(ar_version)
|
44
36
|
puts "----> Switching ActiveRecord to version #{ar_version}"
|
45
|
-
cmd("ACTIVE_RECORD_VERSION=#{ar_version} bundle update
|
37
|
+
cmd("ACTIVE_RECORD_VERSION=#{ar_version} bundle update")
|
46
38
|
|
47
39
|
@database_adapters.each do |adapter|
|
48
40
|
puts "----> Running tests with ActiveRecord #{ar_version} and #{adapter} adapter"
|
@@ -15,6 +15,7 @@ module ActiveRecord
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def merge_withs
|
18
|
+
relation.recursive_with = true if other.recursive_with?
|
18
19
|
other_values = other.with_values.reject { |value| relation.with_values.include?(value) }
|
19
20
|
relation.with!(*other_values) if other_values.any?
|
20
21
|
end
|
@@ -30,7 +31,12 @@ module ActiveRecord
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def with!(opts, *rest)
|
33
|
-
|
34
|
+
if opts == :recursive
|
35
|
+
self.recursive_with = true
|
36
|
+
self.with_values += rest
|
37
|
+
else
|
38
|
+
self.with_values += [opts] + rest
|
39
|
+
end
|
34
40
|
self
|
35
41
|
end
|
36
42
|
|
@@ -44,9 +50,19 @@ module ActiveRecord
|
|
44
50
|
@values[:with] = values
|
45
51
|
end
|
46
52
|
|
53
|
+
def recursive_with?
|
54
|
+
@values[:recursive_with]
|
55
|
+
end
|
56
|
+
|
57
|
+
def recursive_with=(value)
|
58
|
+
raise ImmutableRelation if @loaded
|
59
|
+
|
60
|
+
@values[:recursive_with] = value
|
61
|
+
end
|
62
|
+
|
47
63
|
private
|
48
64
|
|
49
|
-
def build_arel(*args
|
65
|
+
def build_arel(*args)
|
50
66
|
arel = super
|
51
67
|
build_with(arel) if @values[:with]
|
52
68
|
arel
|
@@ -55,7 +71,6 @@ module ActiveRecord
|
|
55
71
|
def build_with(arel) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
|
56
72
|
return if with_values.empty?
|
57
73
|
|
58
|
-
recursive = with_values.delete(:recursive)
|
59
74
|
with_statements = with_values.map do |with_value|
|
60
75
|
case with_value
|
61
76
|
when String then Arel::Nodes::SqlLiteral.new(with_value)
|
@@ -67,7 +82,7 @@ module ActiveRecord
|
|
67
82
|
end
|
68
83
|
end
|
69
84
|
|
70
|
-
|
85
|
+
recursive_with? ? arel.with(:recursive, with_statements) : arel.with(with_statements)
|
71
86
|
end
|
72
87
|
|
73
88
|
def build_with_value_from_array(array)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlado Cingel
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -174,7 +174,7 @@ metadata:
|
|
174
174
|
allowed_push_host: https://rubygems.org
|
175
175
|
homepage_uri: https://github.com/vlado/activerecord-cte
|
176
176
|
source_code_uri: https://github.com/vlado/activerecord-cte
|
177
|
-
post_install_message:
|
177
|
+
post_install_message:
|
178
178
|
rdoc_options: []
|
179
179
|
require_paths:
|
180
180
|
- lib
|
@@ -189,8 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
193
|
-
signing_key:
|
192
|
+
rubygems_version: 3.3.11
|
193
|
+
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Brings Common Table Expressions support to ActiveRecord and makes it super
|
196
196
|
easy to build and chain complex CTE queries
|