active_record_extended 3.2.1 → 3.4.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/README.md +9 -9
- data/lib/active_record_extended/arel/nodes.rb +0 -4
- data/lib/active_record_extended/arel/visitors/postgresql_decorator.rb +0 -23
- data/lib/active_record_extended/patch/array_handler_patch.rb +1 -1
- data/lib/active_record_extended/query_methods/foster_select.rb +1 -1
- data/lib/active_record_extended/query_methods/json.rb +1 -1
- data/lib/active_record_extended/query_methods/unionize.rb +15 -12
- data/lib/active_record_extended/query_methods/where_chain.rb +2 -25
- data/lib/active_record_extended/query_methods/with_cte.rb +8 -1
- data/lib/active_record_extended/utilities/support.rb +1 -1
- data/lib/active_record_extended/version.rb +1 -1
- data/lib/active_record_extended.rb +2 -1
- metadata +6 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9536d7712c3ce9ae40dd62525b5799ff2848e5ba94092c3f6d3c995ffe5467c
|
4
|
+
data.tar.gz: deb23d8497e024312c99a0a24723b7ffba98dc60d9f7027863b3c2901ee0070e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff01f56a0b3fad3363809e3e89eac38642990beed9650c72573636581b1f7f8aed2ccefc5c4e74118be402fe180aaf2bdd8f12bd32d03a99fb172afe6aa8293d
|
7
|
+
data.tar.gz: f35c78ca01d1280638622f04aa1520999f3fb6f8d2ea1fc3949890b8949d5e644025fc5da97393e68e08dd4076589c9f6271374b06e84ed1bdac7af4a14dbf60
|
data/README.md
CHANGED
@@ -51,13 +51,13 @@ Active Record Extended is essentially providing users with the other half of Pos
|
|
51
51
|
|
52
52
|
## Compatibility
|
53
53
|
|
54
|
-
This package is designed align and work with any officially supported Ruby and Rails versions.
|
55
|
-
- Minimum Ruby Version:
|
56
|
-
- Minimum Rails Version:
|
57
|
-
- Minimum Postgres Version:
|
58
|
-
- Latest Ruby supported: 3.
|
59
|
-
- Latest Rails supported:
|
60
|
-
- Postgres: 11-current(
|
54
|
+
This package is designed to align and work with any officially supported Ruby and Rails versions.
|
55
|
+
- Minimum Ruby Version: 3.1.x **(EOL warning!)**
|
56
|
+
- Minimum Rails Version: 6.1.x **(EOL warning!)**
|
57
|
+
- Minimum Postgres Version: 12.x **(EOL warning!)**
|
58
|
+
- Latest Ruby supported: 3.4.x
|
59
|
+
- Latest Rails supported: 8.0.x
|
60
|
+
- Postgres: 11-current(18) (probably works with most older versions to a certain point)
|
61
61
|
|
62
62
|
## Installation
|
63
63
|
|
@@ -560,7 +560,7 @@ As a means for taking complex query logic and transform them into a single or m
|
|
560
560
|
|
561
561
|
**Options:**
|
562
562
|
- `as`: [Symbol or String] (defaults to `"results"`): What the column will be aliased to
|
563
|
-
- `value`: [Symbol or String] (defaults to `key` argument): How the response should
|
563
|
+
- `value`: [Symbol or String] (defaults to `key` argument): How the response should handle the json value return
|
564
564
|
|
565
565
|
See the included example on [Row To JSON](#row-to-json) to see it in action.
|
566
566
|
|
@@ -606,7 +606,7 @@ There's an issue with providing a single union clause and chaining it with a dif
|
|
606
606
|
This is due to requirements of grouping SQL statements. The issue is being working on, but with no ETA.
|
607
607
|
|
608
608
|
This issue only applies to the first initial set of unions and is recommended that you union two relations right off the bat.
|
609
|
-
|
609
|
+
Afterwards you can union/chain single relations.
|
610
610
|
|
611
611
|
Example
|
612
612
|
|
@@ -5,10 +5,6 @@ require "arel/nodes/function"
|
|
5
5
|
|
6
6
|
module Arel
|
7
7
|
module Nodes
|
8
|
-
unless ActiveRecordExtended::AR_VERSION_GTE_6_1
|
9
|
-
["Contains", "Overlaps"].each { |binary_node_name| const_set(binary_node_name, Class.new(::Arel::Nodes::Binary)) }
|
10
|
-
end
|
11
|
-
|
12
8
|
[
|
13
9
|
"ContainsHStore",
|
14
10
|
"ContainsArray",
|
@@ -8,29 +8,6 @@ module ActiveRecordExtended
|
|
8
8
|
private
|
9
9
|
|
10
10
|
# rubocop:disable Naming/MethodName
|
11
|
-
|
12
|
-
unless ActiveRecordExtended::AR_VERSION_GTE_6_1
|
13
|
-
def visit_Arel_Nodes_Overlaps(object, collector)
|
14
|
-
infix_value object, collector, " && "
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
unless ActiveRecordExtended::AR_VERSION_GTE_6_1
|
19
|
-
def visit_Arel_Nodes_Contains(object, collector)
|
20
|
-
left_column = object.left.relation.name.classify.constantize.columns.detect do |col|
|
21
|
-
matchable_column?(col, object)
|
22
|
-
end
|
23
|
-
|
24
|
-
if [:hstore, :jsonb].include?(left_column&.type)
|
25
|
-
visit_Arel_Nodes_ContainsHStore(object, collector)
|
26
|
-
elsif left_column.try(:array)
|
27
|
-
visit_Arel_Nodes_ContainsArray(object, collector)
|
28
|
-
else
|
29
|
-
visit_Arel_Nodes_Inet_Contains(object, collector)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
11
|
def visit_Arel_Nodes_ContainsArray(object, collector)
|
35
12
|
infix_value object, collector, " @> "
|
36
13
|
end
|
@@ -7,7 +7,7 @@ module ActiveRecordExtended
|
|
7
7
|
include ActiveRecordExtended::Utilities::Support
|
8
8
|
include ActiveRecordExtended::Utilities::OrderBy
|
9
9
|
|
10
|
-
AGGREGATE_ONE_LINERS = /^(exists|sum|max|min|avg|count|jsonb?_agg|(bit|bool)_(and|or)|xmlagg|array_agg)
|
10
|
+
AGGREGATE_ONE_LINERS = /^(exists|sum|max|min|avg|count|jsonb?_agg|(bit|bool)_(and|or)|xmlagg|array_agg)$/
|
11
11
|
|
12
12
|
def initialize(scope)
|
13
13
|
@scope = scope
|
@@ -263,7 +263,7 @@ module ActiveRecordExtended
|
|
263
263
|
# - as: [Symbol or String] (default="results"): What the column will be aliased to
|
264
264
|
#
|
265
265
|
#
|
266
|
-
# - value: [Symbol or String] (defaults=[key]): How the response should
|
266
|
+
# - value: [Symbol or String] (defaults=[key]): How the response should handle the json value return
|
267
267
|
#
|
268
268
|
# Example:
|
269
269
|
#
|
@@ -3,8 +3,9 @@
|
|
3
3
|
module ActiveRecordExtended
|
4
4
|
module QueryMethods
|
5
5
|
module Unionize
|
6
|
-
UNION_RELATION_METHODS
|
7
|
-
UNIONIZE_METHODS
|
6
|
+
UNION_RELATION_METHODS = [:order_union, :reorder_union, :union_as].freeze
|
7
|
+
UNIONIZE_METHODS = [:union, :union_all, :union_except, :union_intersect].freeze
|
8
|
+
DEFAULT_STORAGE_VALUE = proc { [] }
|
8
9
|
|
9
10
|
class UnionChain
|
10
11
|
include ActiveRecordExtended::Utilities::Support
|
@@ -86,22 +87,24 @@ module ActiveRecordExtended
|
|
86
87
|
end
|
87
88
|
|
88
89
|
{
|
89
|
-
union_values:
|
90
|
-
union_operations:
|
91
|
-
union_ordering_values:
|
92
|
-
unionized_name:
|
90
|
+
union_values: DEFAULT_STORAGE_VALUE,
|
91
|
+
union_operations: DEFAULT_STORAGE_VALUE,
|
92
|
+
union_ordering_values: DEFAULT_STORAGE_VALUE,
|
93
|
+
unionized_name: proc { arel_table.name }
|
93
94
|
}.each_pair do |method_name, default|
|
94
95
|
define_method(method_name) do
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
if send(:"#{method_name}?")
|
97
|
+
unionize_storage[method_name]
|
98
|
+
else
|
99
|
+
instance_eval(&default)
|
100
|
+
end
|
98
101
|
end
|
99
102
|
|
100
|
-
define_method("#{method_name}?") do
|
103
|
+
define_method(:"#{method_name}?") do
|
101
104
|
unionize_storage.key?(method_name) && !unionize_storage[method_name].presence.nil?
|
102
105
|
end
|
103
106
|
|
104
|
-
define_method("#{method_name}=") do |value|
|
107
|
+
define_method(:"#{method_name}=") do |value|
|
105
108
|
unionize_storage![method_name] = value
|
106
109
|
end
|
107
110
|
end
|
@@ -141,7 +144,7 @@ module ActiveRecordExtended
|
|
141
144
|
|
142
145
|
protected
|
143
146
|
|
144
|
-
def build_unions(arel
|
147
|
+
def build_unions(arel)
|
145
148
|
return unless union_values?
|
146
149
|
|
147
150
|
union_nodes = apply_union_ordering(build_union_nodes!)
|
@@ -46,26 +46,7 @@ module ActiveRecordExtended
|
|
46
46
|
# # SELECT tags.* FROM tags INNER JOIN user on user.id = tags.user_id WHERE user.data @> { nickname: 'chainer' }
|
47
47
|
#
|
48
48
|
def contains(opts, *rest)
|
49
|
-
|
50
|
-
return substitute_comparisons(opts, rest, Arel::Nodes::Contains, "contains")
|
51
|
-
end
|
52
|
-
|
53
|
-
build_where_chain(opts, rest) do |arel|
|
54
|
-
case arel
|
55
|
-
when Arel::Nodes::In, Arel::Nodes::Equality
|
56
|
-
column = left_column(arel) || column_from_association(arel)
|
57
|
-
|
58
|
-
if [:hstore, :jsonb].include?(column.type)
|
59
|
-
Arel::Nodes::ContainsHStore.new(arel.left, arel.right)
|
60
|
-
elsif column.try(:array)
|
61
|
-
Arel::Nodes::ContainsArray.new(arel.left, arel.right)
|
62
|
-
else
|
63
|
-
raise ArgumentError.new("Invalid argument for .where.contains(), got #{arel.class}")
|
64
|
-
end
|
65
|
-
else
|
66
|
-
raise ArgumentError.new("Invalid argument for .where.contains(), got #{arel.class}")
|
67
|
-
end
|
68
|
-
end
|
49
|
+
substitute_comparisons(opts, rest, Arel::Nodes::Contains, "contains")
|
69
50
|
end
|
70
51
|
|
71
52
|
private
|
@@ -111,11 +92,7 @@ module ActiveRecordExtended
|
|
111
92
|
end
|
112
93
|
|
113
94
|
def build_where_clause_for(scope, opts, rest)
|
114
|
-
|
115
|
-
scope.send(:build_where_clause, opts, rest)
|
116
|
-
else
|
117
|
-
scope.send(:where_clause_factory).build(opts, rest)
|
118
|
-
end
|
95
|
+
scope.send(:build_where_clause, opts, rest)
|
119
96
|
end
|
120
97
|
end
|
121
98
|
end
|
@@ -44,7 +44,7 @@ module ActiveRecordExtended
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# @param [Hash, WithCTE] value
|
47
|
-
def pipe_cte_with!(value)
|
47
|
+
def pipe_cte_with!(value) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
|
48
48
|
return if value.nil? || value.empty?
|
49
49
|
|
50
50
|
value.each_pair do |name, expression|
|
@@ -54,6 +54,8 @@ module ActiveRecordExtended
|
|
54
54
|
# Ensure we follow FIFO pattern.
|
55
55
|
# If the parent has similar CTE alias keys, we want to favor the parent's expressions over its children's.
|
56
56
|
if expression.is_a?(ActiveRecord::Relation) && expression.with_values?
|
57
|
+
expression.cte = expression.cte.dup if expression.cte
|
58
|
+
|
57
59
|
# Add child's materialized keys to the parent
|
58
60
|
@materialized_keys += expression.cte.materialized_keys
|
59
61
|
@not_materialized_keys += expression.cte.not_materialized_keys
|
@@ -136,6 +138,11 @@ module ActiveRecordExtended
|
|
136
138
|
!(cte.nil? || cte.empty?)
|
137
139
|
end
|
138
140
|
|
141
|
+
# @return [Array<Hash>]
|
142
|
+
def with_values
|
143
|
+
with_values? ? [cte.with_values] : []
|
144
|
+
end
|
145
|
+
|
139
146
|
# @param [Hash, WithCTE] values
|
140
147
|
def with_values=(values)
|
141
148
|
cte.with_values = values
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "active_record_extended/version"
|
4
4
|
|
5
|
+
require "logger"
|
5
6
|
require "active_record"
|
6
7
|
require "active_record/relation"
|
7
8
|
require "active_record/relation/merger"
|
@@ -10,7 +11,7 @@ require "active_record/relation/query_methods"
|
|
10
11
|
module ActiveRecordExtended
|
11
12
|
extend ActiveSupport::Autoload
|
12
13
|
|
13
|
-
|
14
|
+
AR_VERSION_GTE_8_0 = Gem::Requirement.new(">= 8.0").satisfied_by?(ActiveRecord.gem_version)
|
14
15
|
|
15
16
|
module Utilities
|
16
17
|
extend ActiveSupport::Autoload
|
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_extended
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- George Protacio-Karaszi
|
8
8
|
- Dan McClain
|
9
9
|
- Olivier El Mekki
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: activerecord
|
@@ -21,7 +20,7 @@ dependencies:
|
|
21
20
|
version: '5.2'
|
22
21
|
- - "<"
|
23
22
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
23
|
+
version: '8.1'
|
25
24
|
type: :runtime
|
26
25
|
prerelease: false
|
27
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +30,7 @@ dependencies:
|
|
31
30
|
version: '5.2'
|
32
31
|
- - "<"
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
33
|
+
version: '8.1'
|
35
34
|
- !ruby/object:Gem::Dependency
|
36
35
|
name: pg
|
37
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,96 +45,6 @@ dependencies:
|
|
46
45
|
- - "<"
|
47
46
|
- !ruby/object:Gem::Version
|
48
47
|
version: '3.0'
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: bundler
|
51
|
-
requirement: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '2.2'
|
56
|
-
- - "<"
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: '3.0'
|
59
|
-
type: :development
|
60
|
-
prerelease: false
|
61
|
-
version_requirements: !ruby/object:Gem::Requirement
|
62
|
-
requirements:
|
63
|
-
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: '2.2'
|
66
|
-
- - "<"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: database_cleaner
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '2.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '2.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rake
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '10.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '10.0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec-sqlimit
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.0.5
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.0.5
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: simplecov
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.16'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.16'
|
139
48
|
description: Adds extended functionality to Activerecord Postgres implementation
|
140
49
|
email:
|
141
50
|
- georgekaraszi@gmail.com
|
@@ -173,7 +82,6 @@ licenses:
|
|
173
82
|
- MIT
|
174
83
|
metadata:
|
175
84
|
rubygems_mfa_required: 'true'
|
176
|
-
post_install_message:
|
177
85
|
rdoc_options: []
|
178
86
|
require_paths:
|
179
87
|
- lib
|
@@ -181,15 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
89
|
requirements:
|
182
90
|
- - ">="
|
183
91
|
- !ruby/object:Gem::Version
|
184
|
-
version: '
|
92
|
+
version: '3.1'
|
185
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
94
|
requirements:
|
187
95
|
- - ">="
|
188
96
|
- !ruby/object:Gem::Version
|
189
97
|
version: '0'
|
190
98
|
requirements: []
|
191
|
-
rubygems_version: 3.
|
192
|
-
signing_key:
|
99
|
+
rubygems_version: 3.7.2
|
193
100
|
specification_version: 4
|
194
101
|
summary: Adds extended functionality to Activerecord Postgres implementation
|
195
102
|
test_files: []
|