torque-postgresql 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torque/postgresql/arel.rb +0 -1
- data/lib/torque/postgresql/arel/select_manager.rb +0 -6
- data/lib/torque/postgresql/arel/visitors.rb +0 -7
- data/lib/torque/postgresql/attributes/enum.rb +8 -1
- data/lib/torque/postgresql/relation.rb +25 -2
- data/lib/torque/postgresql/relation/auxiliary_statement.rb +1 -1
- data/lib/torque/postgresql/relation/inheritance.rb +3 -3
- data/lib/torque/postgresql/relation/merger.rb +6 -0
- data/lib/torque/postgresql/version.rb +1 -1
- metadata +2 -3
- data/lib/torque/postgresql/arel/using.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f01743d0b17376aff113086782016f688330d7fe
|
4
|
+
data.tar.gz: bf8ab5b19862bef0a158d5cf17575960f6385b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aab3f50ac0d003ffe4876aef773afe975739eceb2e4552e0789d864b2c6e52669f25ef3bcf30f9c2aed48e9628d01137763fea0fa005d97d538f2974f464ad2
|
7
|
+
data.tar.gz: 60a4e728532be8c9ae45448192762ac4755a8157dc299495d5087a11d80a6f8a3315400eccd11b0f2c471a928406de642dd6af2cd75164b7169c9ae1763c7362
|
@@ -16,13 +16,6 @@ module Torque
|
|
16
16
|
super
|
17
17
|
end
|
18
18
|
|
19
|
-
# Add USING modifier to query
|
20
|
-
def visit_Torque_PostgreSQL_Arel_Using(o, collector)
|
21
|
-
collector << 'USING ( '
|
22
|
-
collector << o.expr
|
23
|
-
collector << ' )'
|
24
|
-
end
|
25
|
-
|
26
19
|
end
|
27
20
|
|
28
21
|
::Arel::Visitors::PostgreSQL.include Visitors
|
@@ -9,7 +9,9 @@ module Torque
|
|
9
9
|
LAZY_VALUE = 0.chr
|
10
10
|
|
11
11
|
class << self
|
12
|
-
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
delegate :each, :sample, to: :members
|
13
15
|
|
14
16
|
# Find or create the class that will handle the value
|
15
17
|
def lookup(name)
|
@@ -40,6 +42,11 @@ module Torque
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
# Different from values, it returns the list of items already casted
|
46
|
+
def members
|
47
|
+
values.dup.map(&method(:new))
|
48
|
+
end
|
49
|
+
|
43
50
|
# Fetch a value from the list
|
44
51
|
# see https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/fixtures.rb#L656
|
45
52
|
# see https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/validations/uniqueness.rb#L101
|
@@ -14,9 +14,22 @@ module Torque
|
|
14
14
|
include Inheritance
|
15
15
|
|
16
16
|
SINGLE_VALUE_METHODS = [:itself_only]
|
17
|
-
MULTI_VALUE_METHODS = [:distinct_on, :auxiliary_statements, :cast_records
|
17
|
+
MULTI_VALUE_METHODS = [:distinct_on, :auxiliary_statements, :cast_records,
|
18
|
+
:dynamic_selection]
|
18
19
|
VALUE_METHODS = SINGLE_VALUE_METHODS + MULTI_VALUE_METHODS
|
19
20
|
|
21
|
+
# :nodoc:
|
22
|
+
def dynamic_selection_values; get_value(:dynamic_selection); end
|
23
|
+
# :nodoc:
|
24
|
+
def dynamic_selection_values=(value); set_value(:dynamic_selection, value); end
|
25
|
+
|
26
|
+
# Resolve column name when calculating models, allowing the column name to
|
27
|
+
# be more complex while keeping the query selection quality
|
28
|
+
def calculate(operation, column_name)
|
29
|
+
column_name = resolve_column(column_name).first if column_name.is_a?(Hash)
|
30
|
+
super(operation, column_name)
|
31
|
+
end
|
32
|
+
|
20
33
|
# Resolve column definition up to second value.
|
21
34
|
# For example, based on Post model:
|
22
35
|
#
|
@@ -65,6 +78,16 @@ module Torque
|
|
65
78
|
|
66
79
|
private
|
67
80
|
|
81
|
+
def dynamic_selection
|
82
|
+
@dynamic_selection ||= []
|
83
|
+
end
|
84
|
+
|
85
|
+
def build_arel
|
86
|
+
arel = super
|
87
|
+
arel.project(*dynamic_selection) if select_values.blank? && dynamic_selection.any?
|
88
|
+
arel
|
89
|
+
end
|
90
|
+
|
68
91
|
# Compatibility method with 5.0
|
69
92
|
unless ActiveRecord::Relation.method_defined?(:get_value)
|
70
93
|
def get_value(name)
|
@@ -108,7 +131,7 @@ module Torque
|
|
108
131
|
ActiveRecord::Relation::MULTI_VALUE_METHODS += Relation::MULTI_VALUE_METHODS
|
109
132
|
ActiveRecord::Relation::VALUE_METHODS += Relation::VALUE_METHODS
|
110
133
|
ActiveRecord::QueryMethods::VALID_UNSCOPING_VALUES += [:cast_records, :itself_only,
|
111
|
-
:distinct_on, :auxiliary_statements]
|
134
|
+
:distinct_on, :auxiliary_statements, :dynamic_selection]
|
112
135
|
|
113
136
|
if ActiveRecord::QueryMethods.const_defined?('DEFAULT_VALUES')
|
114
137
|
Relation::SINGLE_VALUE_METHODS.each do |value|
|
@@ -73,19 +73,19 @@ module Torque
|
|
73
73
|
end
|
74
74
|
|
75
75
|
columns.push(build_auto_caster_marker(arel, self.cast_records_value))
|
76
|
-
|
76
|
+
dynamic_selection.concat(columns) if columns.any?
|
77
77
|
end
|
78
78
|
|
79
79
|
# Build as many left outer join as necessary for each dependent table
|
80
80
|
def build_inheritances_joins(arel, types)
|
81
81
|
columns = Hash.new{ |h, k| h[k] = [] }
|
82
|
-
|
82
|
+
base_on_key = model.arel_table[primary_key]
|
83
83
|
base_attributes = model.attribute_names
|
84
84
|
|
85
85
|
# Iterate over each casted dependent calculating the columns
|
86
86
|
types.each.with_index do |model, idx|
|
87
87
|
join_table = model.arel_table.alias("\"i_#{idx}\"")
|
88
|
-
arel.outer_join(join_table).
|
88
|
+
arel.outer_join(join_table).on(base_on_key.eq(join_table[primary_key]))
|
89
89
|
(model.attribute_names - base_attributes).each do |column|
|
90
90
|
columns[column] << join_table
|
91
91
|
end
|
@@ -6,6 +6,7 @@ module Torque
|
|
6
6
|
def merge # :nodoc:
|
7
7
|
super
|
8
8
|
|
9
|
+
merge_dynamic_selection
|
9
10
|
merge_distinct_on
|
10
11
|
merge_auxiliary_statements
|
11
12
|
merge_inheritance
|
@@ -15,6 +16,11 @@ module Torque
|
|
15
16
|
|
16
17
|
private
|
17
18
|
|
19
|
+
# Merge dynamic selection columns
|
20
|
+
def merge_dynamic_selection
|
21
|
+
relation.dynamic_selection_values.concat(other.dynamic_selection_values)
|
22
|
+
end
|
23
|
+
|
18
24
|
# Merge distinct on columns
|
19
25
|
def merge_distinct_on
|
20
26
|
return if other.distinct_on_values.blank?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -190,7 +190,6 @@ files:
|
|
190
190
|
- lib/torque/postgresql/arel.rb
|
191
191
|
- lib/torque/postgresql/arel/join_source.rb
|
192
192
|
- lib/torque/postgresql/arel/select_manager.rb
|
193
|
-
- lib/torque/postgresql/arel/using.rb
|
194
193
|
- lib/torque/postgresql/arel/visitors.rb
|
195
194
|
- lib/torque/postgresql/attributes.rb
|
196
195
|
- lib/torque/postgresql/attributes/builder.rb
|