postgres_with 1.0.0 → 2.0.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/lib/postgres_with/active_record/querying.rb +0 -8
- data/lib/postgres_with/active_record/relation/query_methods.rb +35 -15
- data/lib/postgres_with/active_record.rb +0 -1
- data/lib/postgres_with/arel/visitors/to_sql.rb +1 -1
- data/lib/postgres_with/version.rb +1 -1
- data/postgres_with.gemspec +1 -2
- metadata +4 -19
- data/lib/postgres_with/active_record/cte_proxy.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8409fb5b221c7a249a1adbf85b061eb5891f026564428ba10ffa081281611c90
|
4
|
+
data.tar.gz: 41d699850f0d02e70147007d605e8b791186313e393e161012121e2a98eb26fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e82d755b9e450e56495a3cae357aa2614c6408849924db5cc80c208c417da4505fdf6b2a429470cafc6fb10165a46c7b12b7069c0d83e0f84826b326c4354e19
|
7
|
+
data.tar.gz: bb72286a14385f7f4c2da6bf1f631c6167d82ec36c35b7d15f9babcd1eee4364fe9a0b6a710adc844e7f8a5308715e7eca9dc3fcc5af2aff6c76522d4a432a72
|
@@ -1,11 +1,3 @@
|
|
1
1
|
module ActiveRecord::Querying
|
2
2
|
delegate :with, to: :all
|
3
|
-
|
4
|
-
def from_cte(name, expression)
|
5
|
-
table = Arel::Table.new(name)
|
6
|
-
|
7
|
-
cte_proxy = CTEProxy.new(name, self)
|
8
|
-
relation = ActiveRecord::Relation.new cte_proxy, cte_proxy.arel_table
|
9
|
-
relation.with name => expression
|
10
|
-
end
|
11
3
|
end
|
@@ -81,24 +81,15 @@ module ActiveRecord
|
|
81
81
|
with_statements = with_values.flat_map do |with_value|
|
82
82
|
case with_value
|
83
83
|
when String
|
84
|
-
with_value
|
84
|
+
Arel::Nodes::SqlLiteral.new(with_value)
|
85
85
|
when Hash
|
86
|
-
with_value
|
87
|
-
case expression
|
88
|
-
when String
|
89
|
-
select = Arel::Nodes::SqlLiteral.new "(#{expression})"
|
90
|
-
when ActiveRecord::Relation, Arel::SelectManager
|
91
|
-
select = Arel::Nodes::SqlLiteral.new "(#{expression.to_sql})"
|
92
|
-
end
|
93
|
-
if name.to_s.start_with?('_materialized_')
|
94
|
-
name = name.gsub('_materialized_', '')
|
95
|
-
Arel::Nodes::AsMaterialized.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select
|
96
|
-
else
|
97
|
-
Arel::Nodes::As.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select
|
98
|
-
end
|
99
|
-
end
|
86
|
+
build_arel_from_hash(with_value)
|
100
87
|
when Arel::Nodes::As
|
101
88
|
with_value
|
89
|
+
when Array
|
90
|
+
build_arel_from_array(with_value)
|
91
|
+
else
|
92
|
+
raise ArgumentError, "Unsupported argument type: #{with_value} #{with_value.class}"
|
102
93
|
end
|
103
94
|
end
|
104
95
|
unless with_statements.empty?
|
@@ -112,6 +103,35 @@ module ActiveRecord
|
|
112
103
|
arel
|
113
104
|
end
|
114
105
|
|
106
|
+
def build_arel_from_hash(with_value)
|
107
|
+
with_value.map do |name, expression|
|
108
|
+
select = case expression
|
109
|
+
when String
|
110
|
+
Arel::Nodes::SqlLiteral.new("(#{expression})")
|
111
|
+
when ActiveRecord::Relation
|
112
|
+
expression.arel
|
113
|
+
when Arel::SelectManager
|
114
|
+
expression
|
115
|
+
end
|
116
|
+
if name.to_s.start_with?('_materialized_')
|
117
|
+
name = name.gsub('_materialized_', '')
|
118
|
+
table = Arel::Table.new(name)
|
119
|
+
Arel::Nodes::AsMaterialized.new(table, select)
|
120
|
+
else
|
121
|
+
table = Arel::Table.new(name)
|
122
|
+
Arel::Nodes::As.new(table, select)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def build_arel_from_array(array)
|
128
|
+
unless array.map(&:class).uniq == [Arel::Nodes::As]
|
129
|
+
raise ArgumentError, "Unsupported argument type: #{array} #{array.class}"
|
130
|
+
end
|
131
|
+
|
132
|
+
array
|
133
|
+
end
|
134
|
+
|
115
135
|
alias_method :build_arel_without_extensions, :build_arel
|
116
136
|
alias_method :build_arel, :build_arel_with_extensions
|
117
137
|
end
|
data/postgres_with.gemspec
CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = PostgresWith::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'activerecord', '
|
19
|
-
gem.add_dependency 'arel', '>= 4.0'
|
18
|
+
gem.add_dependency 'activerecord', '>= 6.0'
|
20
19
|
|
21
20
|
gem.add_development_dependency 'pg', '>= 0.13'
|
22
21
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postgres_with
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Neier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '5.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '5.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: arel
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
19
|
+
version: '6.0'
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '6.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: pg
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,7 +51,6 @@ files:
|
|
65
51
|
- Rakefile
|
66
52
|
- lib/postgres_with.rb
|
67
53
|
- lib/postgres_with/active_record.rb
|
68
|
-
- lib/postgres_with/active_record/cte_proxy.rb
|
69
54
|
- lib/postgres_with/active_record/querying.rb
|
70
55
|
- lib/postgres_with/active_record/relation.rb
|
71
56
|
- lib/postgres_with/active_record/relation/merger.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
class CTEProxy
|
2
|
-
include ActiveRecord::Querying
|
3
|
-
include ActiveRecord::Sanitization::ClassMethods
|
4
|
-
include ActiveRecord::Reflection::ClassMethods
|
5
|
-
|
6
|
-
attr_accessor :reflections, :current_scope
|
7
|
-
attr_reader :connection, :arel_table
|
8
|
-
|
9
|
-
def initialize(name, model)
|
10
|
-
@name = name
|
11
|
-
@arel_table = Arel::Table.new(name)
|
12
|
-
@model = model
|
13
|
-
@connection = model.connection
|
14
|
-
@_reflections = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
def name
|
18
|
-
@name
|
19
|
-
end
|
20
|
-
|
21
|
-
def table_name
|
22
|
-
name
|
23
|
-
end
|
24
|
-
|
25
|
-
delegate :column_names, :columns_hash, :model_name, :primary_key, :attribute_alias?,
|
26
|
-
:aggregate_reflections, :instantiate, :type_for_attribute, :relation_delegate_class, to: :@model
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def reflections
|
31
|
-
@_reflections
|
32
|
-
end
|
33
|
-
|
34
|
-
alias _reflections reflections
|
35
|
-
end
|