torque-postgresql 0.1.0 → 0.1.1
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/torque/postgresql.rb +2 -0
- data/lib/torque/postgresql/adapter/database_statements.rb +1 -1
- data/lib/torque/postgresql/adapter/oid.rb +0 -1
- data/lib/torque/postgresql/attributes/builder/enum.rb +2 -2
- data/lib/torque/postgresql/attributes/enum.rb +1 -1
- data/lib/torque/postgresql/auxiliary_statement.rb +182 -55
- data/lib/torque/postgresql/auxiliary_statement/settings.rb +48 -0
- data/lib/torque/postgresql/config.rb +9 -0
- data/lib/torque/postgresql/i18n.rb +17 -0
- data/lib/torque/postgresql/relation/auxiliary_statement.rb +9 -15
- data/lib/torque/postgresql/version.rb +1 -1
- metadata +8 -7
- data/lib/torque/postgresql/adapter/oid/array.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3d142177c865c53b93ad0cb573190bfa6ef2e8a
|
4
|
+
data.tar.gz: a3918f964ab43868da70397ef8c8c43b45f5b10c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85930c4a51a9684caf780ae88d5a25b965f3a24c0112a20b3a90216e714a106b9738b56b889598d6e446ab1a75ab6fbc92c69847ee0414edc0d5aaa4c5e93f86
|
7
|
+
data.tar.gz: 08bebcce0d9e68da7c937582d5988d40038738c3c850d26842d3ec04e95c63cd07f2a394ce83a8aee035ddf36253d6bbf619a16ac43ef1e041913cb35dee205d
|
data/lib/torque/postgresql.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'i18n'
|
1
2
|
require 'active_model'
|
2
3
|
require 'active_record'
|
3
4
|
require 'active_support'
|
@@ -9,6 +10,7 @@ require 'torque/postgresql/config'
|
|
9
10
|
require 'torque/postgresql/version'
|
10
11
|
require 'torque/postgresql/collector'
|
11
12
|
|
13
|
+
require 'torque/postgresql/i18n'
|
12
14
|
require 'torque/postgresql/adapter'
|
13
15
|
require 'torque/postgresql/attributes'
|
14
16
|
require 'torque/postgresql/auxiliary_statement'
|
@@ -46,7 +46,7 @@ module Torque
|
|
46
46
|
INNER JOIN pg_type a ON (a.oid = t.typarray)
|
47
47
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
48
48
|
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
49
|
-
AND t.typtype IN ( '
|
49
|
+
AND t.typtype IN ( 'e' )
|
50
50
|
#{filter}
|
51
51
|
AND NOT EXISTS(
|
52
52
|
SELECT 1 FROM pg_catalog.pg_type el
|
@@ -64,13 +64,13 @@ module Torque
|
|
64
64
|
return false
|
65
65
|
rescue Interrupt => err
|
66
66
|
if !initial
|
67
|
-
raise ArgumentError, <<-MSG.gsub(
|
67
|
+
raise ArgumentError, <<-MSG.strip.gsub(/\n +/, ' ')
|
68
68
|
#{subtype.class.name} was not able to generate requested
|
69
69
|
methods because the method #{err} already exists in
|
70
70
|
#{klass.name}.
|
71
71
|
MSG
|
72
72
|
else
|
73
|
-
warn <<-MSG.gsub(
|
73
|
+
warn <<-MSG.strip.gsub(/\n +/, ' ')
|
74
74
|
#{subtype.class.name} was not able to autoload on
|
75
75
|
#{klass.name} because the method #{err} already exists.
|
76
76
|
MSG
|
@@ -137,7 +137,7 @@ module Torque
|
|
137
137
|
# Get a translated version of the value
|
138
138
|
def text(attr = nil, model = nil)
|
139
139
|
keys = i18n_keys(attr, model) << self.underscore.humanize
|
140
|
-
I18n.
|
140
|
+
::I18n.translate(keys.shift, default: keys)
|
141
141
|
end
|
142
142
|
|
143
143
|
# Change the string result for lazy value
|
@@ -1,10 +1,9 @@
|
|
1
|
+
require_relative 'auxiliary_statement/settings'
|
2
|
+
|
1
3
|
module Torque
|
2
4
|
module PostgreSQL
|
3
5
|
class AuxiliaryStatement
|
4
6
|
|
5
|
-
# The settings collector class
|
6
|
-
Settings = Collector.new(:attributes, :join, :join_type, :query)
|
7
|
-
|
8
7
|
class << self
|
9
8
|
# These attributes require that the class is setup
|
10
9
|
#
|
@@ -12,8 +11,8 @@ module Torque
|
|
12
11
|
# exposed_attributes -> Will be projected to the main query
|
13
12
|
# selected_attributes -> Will be selected on the configurated query
|
14
13
|
# join_attributes -> Will be used to join the the queries
|
15
|
-
[:exposed_attributes, :selected_attributes, :
|
16
|
-
:join_type].each do |attribute|
|
14
|
+
[:exposed_attributes, :selected_attributes, :query, :join_attributes,
|
15
|
+
:join_type, :requires].each do |attribute|
|
17
16
|
define_method(attribute) do
|
18
17
|
setup
|
19
18
|
instance_variable_get("@#{attribute}")
|
@@ -27,11 +26,26 @@ module Torque
|
|
27
26
|
base.const_set(const, Class.new(AuxiliaryStatement))
|
28
27
|
end
|
29
28
|
|
29
|
+
# Create a new instance of an auxiliary statement
|
30
|
+
def instantiate(statement, base, options = nil)
|
31
|
+
klass = base.auxiliary_statements_list[statement]
|
32
|
+
return klass.new(options) unless klass.nil?
|
33
|
+
raise ArgumentError, <<-MSG.strip
|
34
|
+
There's no '#{statement}' auxiliary statement defined for #{base.class.name}.
|
35
|
+
MSG
|
36
|
+
end
|
37
|
+
|
38
|
+
# Identify if the query set may be used as a relation
|
39
|
+
def relation_query?(obj)
|
40
|
+
!obj.nil? && obj.respond_to?(:ancestors) && \
|
41
|
+
obj.ancestors.include?(ActiveRecord::Base)
|
42
|
+
end
|
43
|
+
|
30
44
|
# Set a configuration block, if the class is already set up, just clean
|
31
45
|
# the query and wait it to be setup again
|
32
46
|
def configurator(block)
|
33
47
|
@config = block
|
34
|
-
@query = nil
|
48
|
+
@query = nil
|
35
49
|
end
|
36
50
|
|
37
51
|
# Get the base class associated to this statement
|
@@ -39,14 +53,40 @@ module Torque
|
|
39
53
|
self.parent
|
40
54
|
end
|
41
55
|
|
56
|
+
# Get the name of the base class
|
57
|
+
def base_name
|
58
|
+
base.name
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get the arel version of the statement table
|
62
|
+
def table
|
63
|
+
@table ||= Arel::Table.new(table_name)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get the name of the table of the configurated statement
|
67
|
+
def table_name
|
68
|
+
@table_name ||= self.name.demodulize.split('_').first.underscore
|
69
|
+
end
|
70
|
+
|
42
71
|
# Get the arel table of the base class
|
43
72
|
def base_table
|
44
|
-
base.arel_table
|
73
|
+
@base_table ||= base.arel_table
|
45
74
|
end
|
46
75
|
|
47
76
|
# Get the arel table of the query
|
48
77
|
def query_table
|
49
|
-
query.arel_table
|
78
|
+
@query_table ||= query.arel_table
|
79
|
+
end
|
80
|
+
|
81
|
+
# Project a column on a given table, or use the column table
|
82
|
+
def project(column, arel_table = nil)
|
83
|
+
if column.to_s.include?('.')
|
84
|
+
table_name, column = column.to_s.split('.')
|
85
|
+
arel_table = Arel::Table.new(table_name)
|
86
|
+
end
|
87
|
+
|
88
|
+
arel_table ||= table
|
89
|
+
arel_table[column.to_s]
|
50
90
|
end
|
51
91
|
|
52
92
|
private
|
@@ -62,7 +102,7 @@ module Torque
|
|
62
102
|
|
63
103
|
# Setup the class
|
64
104
|
def setup!
|
65
|
-
# attributes key
|
105
|
+
# attributes key:
|
66
106
|
# Provides a map of attributes to be exposed to the main query.
|
67
107
|
#
|
68
108
|
# For instace, if the statement query has an 'id' column that you
|
@@ -74,7 +114,7 @@ module Torque
|
|
74
114
|
# fields, then:
|
75
115
|
# attributes 'table.name': :item_name
|
76
116
|
#
|
77
|
-
# join_type key
|
117
|
+
# join_type key:
|
78
118
|
# Changes the type of the join and set the constraints
|
79
119
|
#
|
80
120
|
# The left side of the hash is the source table column, the right
|
@@ -87,106 +127,193 @@ module Torque
|
|
87
127
|
# It's possible to change the default type of join
|
88
128
|
# join :left, id: :user_id
|
89
129
|
#
|
90
|
-
# join key
|
130
|
+
# join key:
|
91
131
|
# Changes the type of the join
|
92
132
|
#
|
93
|
-
# query key
|
133
|
+
# query key:
|
94
134
|
# Save the query command to be performand
|
95
|
-
|
135
|
+
#
|
136
|
+
# requires key:
|
137
|
+
# Indicates dependencies with another statements
|
138
|
+
#
|
139
|
+
# polymorphic key:
|
140
|
+
# Indicates a polymorphic relationship, with will affect the way the
|
141
|
+
# auto join works, by giving a polymorphic connection
|
142
|
+
settings = Settings.new(self)
|
96
143
|
@config.call(settings)
|
97
144
|
|
98
|
-
table_name = self.name.demodulize.split('_').first.underscore
|
99
145
|
@join_type = settings.join_type || :inner
|
100
|
-
@
|
146
|
+
@requires = Array[settings.requires].flatten.compact
|
101
147
|
@query = settings.query
|
102
148
|
|
149
|
+
# Manually set the query table when it's not an relation query
|
150
|
+
@query_table = settings.query_table unless relation_query?(@query)
|
151
|
+
|
152
|
+
# Reset all the used attributes
|
103
153
|
@selected_attributes = []
|
104
154
|
@exposed_attributes = []
|
105
155
|
@join_attributes = []
|
106
156
|
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
settings.
|
157
|
+
# Generate attributes projections
|
158
|
+
attributes_projections(settings.attributes)
|
159
|
+
|
160
|
+
# Generate join projections
|
161
|
+
if settings.join.present?
|
162
|
+
joins_projections(settings.join)
|
163
|
+
elsif relation_query?(@query)
|
164
|
+
check_auto_join(settings.polymorphic)
|
165
|
+
else
|
166
|
+
raise ArgumentError, <<-MSG.strip.gsub(/\n +/, ' ')
|
167
|
+
You must provide the join columns when using '#{query.class.name}'
|
168
|
+
as a query object on #{self.class.name}.
|
169
|
+
MSG
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Iterate the attributes settings
|
174
|
+
# Attributes (left => right)
|
175
|
+
# left -> query.selected_attributes AS right
|
176
|
+
# right -> table.exposed_attributes
|
177
|
+
def attributes_projections(list)
|
178
|
+
list.each do |left, right|
|
112
179
|
@exposed_attributes << project(right)
|
113
180
|
@selected_attributes << project(left, query_table).as(right.to_s)
|
114
181
|
end
|
182
|
+
end
|
115
183
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@selected_attributes << project(right, query_table)
|
125
|
-
@join_attributes << project(left, base_table).eq(project(right))
|
126
|
-
end
|
184
|
+
# Iterate the join settings
|
185
|
+
# Join (left => right)
|
186
|
+
# left -> base.join_attributes.eq(right)
|
187
|
+
# right -> table.selected_attributes
|
188
|
+
def joins_projections(list)
|
189
|
+
list.each do |left, right|
|
190
|
+
@selected_attributes << project(right, query_table)
|
191
|
+
@join_attributes << project(left, base_table).eq(project(right))
|
127
192
|
end
|
128
193
|
end
|
129
194
|
|
130
195
|
# Check if it's possible to identify the connection between the main
|
131
196
|
# query and the statement query
|
132
|
-
|
133
|
-
|
197
|
+
#
|
198
|
+
# First, identify the foreign key column name, then check if it exists
|
199
|
+
# on the query and then create the projections
|
200
|
+
def check_auto_join(polymorphic)
|
201
|
+
foreign_key = (polymorphic.present? ? polymorphic : base_name)
|
202
|
+
foreign_key = foreign_key.to_s.foreign_key
|
134
203
|
if query.columns_hash.key?(foreign_key)
|
135
|
-
|
136
|
-
|
137
|
-
|
204
|
+
joins_projections(base.primary_key => foreign_key)
|
205
|
+
if polymorphic.present?
|
206
|
+
foreign_type = project(foreign_key.gsub(/_id$/, '_type'), query_table)
|
207
|
+
@selected_attributes << foreign_type
|
208
|
+
@join_attributes << foreign_type.eq(base_name)
|
209
|
+
end
|
138
210
|
end
|
139
211
|
end
|
140
|
-
|
141
|
-
# Project a column on a given table, or use the column table
|
142
|
-
def project(column, table = @table)
|
143
|
-
if column.to_s.include?('.')
|
144
|
-
table, column = column.split('.')
|
145
|
-
table = Arel::Table.new(table)
|
146
|
-
end
|
147
|
-
|
148
|
-
table[column]
|
149
|
-
end
|
150
212
|
end
|
151
213
|
|
214
|
+
delegate :exposed_attributes, :join_attributes, :selected_attributes, :join_type, :table,
|
215
|
+
:query_table, :base_table, :requires, :project, :relation_query?, to: :class
|
216
|
+
|
152
217
|
# Start a new auxiliary statement giving extra options
|
153
218
|
def initialize(*args)
|
154
|
-
|
219
|
+
options = args.extract_options!
|
220
|
+
uses_key = Torque::PostgreSQL.config.auxiliary_statement.send_arguments_key
|
221
|
+
|
222
|
+
@join = options.fetch(:join, {})
|
223
|
+
@uses = options.fetch(uses_key, [])
|
224
|
+
@select = options.fetch(:select, {})
|
225
|
+
@join_type = options.fetch(:join_type, join_type)
|
155
226
|
end
|
156
227
|
|
157
228
|
# Get the columns that will be selected for this statement
|
158
229
|
def columns
|
159
|
-
|
230
|
+
exposed_attributes + @select.values.map(&method(:project))
|
160
231
|
end
|
161
232
|
|
162
233
|
# Build the statement on the given arel and return the WITH statement
|
163
|
-
def build_arel(arel)
|
164
|
-
|
165
|
-
|
234
|
+
def build_arel(arel, base)
|
235
|
+
list = []
|
236
|
+
|
237
|
+
# Process dependencies
|
238
|
+
if requires.present?
|
239
|
+
requires.each do |dependent|
|
240
|
+
next if base.auxiliary_statements.key?(dependent)
|
241
|
+
|
242
|
+
instance = AuxiliaryStatement.instantiate(dependent, base)
|
243
|
+
base.auxiliary_statements[dependent] = instance
|
244
|
+
list << instance.build_arel(arel, base)
|
245
|
+
end
|
246
|
+
end
|
166
247
|
|
167
248
|
# Build the join for this statement
|
168
|
-
arel.join(
|
249
|
+
arel.join(table, arel_join).on(*join_columns)
|
169
250
|
|
170
251
|
# Return the subquery for this statement
|
171
|
-
Arel::Nodes::As.new(
|
252
|
+
list << Arel::Nodes::As.new(table, mount_query)
|
172
253
|
end
|
173
254
|
|
174
255
|
private
|
175
256
|
|
176
257
|
# Get the class of the join on arel
|
177
258
|
def arel_join
|
178
|
-
case @
|
259
|
+
case @join_type
|
179
260
|
when :inner then Arel::Nodes::InnerJoin
|
180
261
|
when :left then Arel::Nodes::OuterJoin
|
181
262
|
when :right then Arel::Nodes::RightOuterJoin
|
182
263
|
when :full then Arel::Nodes::FullOuterJoin
|
183
264
|
else
|
184
|
-
raise ArgumentError, <<-MSG.
|
265
|
+
raise ArgumentError, <<-MSG.strip
|
185
266
|
The '#{@join_type}' is not implemented as a join type.
|
186
267
|
MSG
|
187
268
|
end
|
188
269
|
end
|
189
270
|
|
271
|
+
# Mount the query base on it's class
|
272
|
+
def mount_query
|
273
|
+
klass = self.class
|
274
|
+
query = klass.query
|
275
|
+
uses = @uses.map(&klass.parent.connection.method(:quote))
|
276
|
+
|
277
|
+
# Call a proc to get the query
|
278
|
+
if query.respond_to?(:call)
|
279
|
+
query = query.call(*uses)
|
280
|
+
uses = []
|
281
|
+
end
|
282
|
+
|
283
|
+
# Prepare the query depending on its type
|
284
|
+
if query.is_a?(String)
|
285
|
+
Arel::Nodes::SqlLiteral.new("(#{query})" % uses)
|
286
|
+
elsif relation_query?(query)
|
287
|
+
query.select(*select_columns).send(:build_arel)
|
288
|
+
else
|
289
|
+
raise ArgumentError, <<-MSG.strip
|
290
|
+
Only String and ActiveRecord::Base objects are accepted as query objects,
|
291
|
+
#{query.class.name} given for #{self.class.name}.
|
292
|
+
MSG
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
# Mount the list of join attributes with the additional ones
|
297
|
+
def join_columns
|
298
|
+
join_attributes + @join.map do |left, right|
|
299
|
+
if right.is_a?(Symbol)
|
300
|
+
project(left, base_table).eq(project(right))
|
301
|
+
else
|
302
|
+
project(left).eq(right)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# Mount the list of selected attributes with the additional ones
|
308
|
+
def select_columns
|
309
|
+
selected_attributes + @select.map do |left, right|
|
310
|
+
project(left, query_table).as(right.to_s)
|
311
|
+
end + @join.map do |left, right|
|
312
|
+
column = right.is_a?(Symbol) ? right : left
|
313
|
+
project(column, query_table)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
190
317
|
end
|
191
318
|
end
|
192
319
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Torque
|
2
|
+
module PostgreSQL
|
3
|
+
class AuxiliaryStatement
|
4
|
+
class Settings < Collector.new(:attributes, :join, :join_type, :query, :requires,
|
5
|
+
:polymorphic)
|
6
|
+
|
7
|
+
attr_reader :source
|
8
|
+
alias cte source
|
9
|
+
|
10
|
+
delegate :base, :base_name, :base_table, :table, :table_name, to: :@source
|
11
|
+
delegate :relation_query?, to: Torque::PostgreSQL::AuxiliaryStatement
|
12
|
+
|
13
|
+
def initialize(source)
|
14
|
+
@source = source
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get the arel version of the table set on the query
|
18
|
+
def query_table
|
19
|
+
raise StandardError, 'The query is not defined yet' if query.nil?
|
20
|
+
return query.arel_table if relation_query?(query)
|
21
|
+
@query_table
|
22
|
+
end
|
23
|
+
|
24
|
+
# There are two ways of setting the query:
|
25
|
+
# - A simple relation based on a modle
|
26
|
+
# - A string or a proc that requires the table name as first argument
|
27
|
+
def query(value = nil, command = nil)
|
28
|
+
return @query if value.nil?
|
29
|
+
return @query = value if relation_query?(value)
|
30
|
+
|
31
|
+
valid_type = command.respond_to?(:call) || command.is_a?(String)
|
32
|
+
raise ArgumentError, <<-MSG.strip.gsub(/\n +/, ' ') if command.nil?
|
33
|
+
To use proc or string as query, you need to provide the table name
|
34
|
+
as the first argument
|
35
|
+
MSG
|
36
|
+
raise ArgumentError, <<-MSG.strip.gsub(/\n +/, ' ') unless valid_type
|
37
|
+
Only relation, string and proc are valid object types for query,
|
38
|
+
#{command.inspect} given.
|
39
|
+
MSG
|
40
|
+
|
41
|
+
@query = command
|
42
|
+
@query_table = Arel::Table.new(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -46,5 +46,14 @@ module Torque
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
+
# Configure auxiliary statement features
|
50
|
+
config.nested(:auxiliary_statement) do |cte|
|
51
|
+
|
52
|
+
# Define the key that is used on auxiliary statements to send extra
|
53
|
+
# arguments to format string or send on a proc
|
54
|
+
cte.send_arguments_key = :uses
|
55
|
+
|
56
|
+
end
|
57
|
+
|
49
58
|
end
|
50
59
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Torque
|
2
|
+
module PostgreSQL
|
3
|
+
module I18n
|
4
|
+
|
5
|
+
# Adds extra suport to localize durations
|
6
|
+
# This is a temporary solution, since 3600.seconds do not translate into
|
7
|
+
# 1 hour
|
8
|
+
def localize(locale, object, format = :default, options = {})
|
9
|
+
return super unless object.is_a?(ActiveSupport::Duration)
|
10
|
+
object.inspect
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
::I18n::Backend::Base.prepend I18n
|
16
|
+
end
|
17
|
+
end
|
@@ -13,21 +13,16 @@ module Torque
|
|
13
13
|
# Like #with, but modifies relation in place.
|
14
14
|
def with!(*args)
|
15
15
|
options = args.extract_options!
|
16
|
-
self.auxiliary_statements ||=
|
16
|
+
self.auxiliary_statements ||= {}
|
17
17
|
args.each do |table|
|
18
|
-
|
19
|
-
raise ArgumentError, <<-MSG.gsub(/^ +| +$|\n/, '')
|
20
|
-
There's no '#{table}' auxiliary statement defined for #{self.class.name}.
|
21
|
-
MSG
|
22
|
-
end
|
23
|
-
|
24
|
-
klass = self.auxiliary_statements_list[table]
|
25
|
-
self.auxiliary_statements << klass.new(options)
|
18
|
+
self.auxiliary_statements[table] = instantiate(table, self, options)
|
26
19
|
end
|
20
|
+
|
27
21
|
self
|
28
22
|
end
|
29
23
|
|
30
24
|
private
|
25
|
+
delegate :instantiate, to: PostgreSQL::AuxiliaryStatement
|
31
26
|
|
32
27
|
# Hook arel build to add the distinct on clause
|
33
28
|
def build_arel
|
@@ -35,12 +30,12 @@ module Torque
|
|
35
30
|
|
36
31
|
if self.auxiliary_statements.present?
|
37
32
|
columns = []
|
38
|
-
subqueries = self.auxiliary_statements.map do |klass|
|
33
|
+
subqueries = self.auxiliary_statements.values.map do |klass|
|
39
34
|
columns << klass.columns
|
40
|
-
klass.build_arel(arel)
|
35
|
+
klass.build_arel(arel, self)
|
41
36
|
end
|
42
37
|
|
43
|
-
arel.with(subqueries)
|
38
|
+
arel.with(subqueries.flatten)
|
44
39
|
if select_values.empty? && columns.any?
|
45
40
|
columns.unshift table[Arel.sql('*')]
|
46
41
|
arel.projections = columns
|
@@ -53,9 +48,8 @@ module Torque
|
|
53
48
|
# Throw an error showing that an auxiliary statement of the given
|
54
49
|
# table name isn't defined
|
55
50
|
def auxiliary_statement_error(name)
|
56
|
-
raise ArgumentError, <<-MSG.
|
57
|
-
There's no '#{name}' auxiliary statement defined for
|
58
|
-
#{self.class.name}.
|
51
|
+
raise ArgumentError, <<-MSG.strip
|
52
|
+
There's no '#{name}' auxiliary statement defined for #{self.class.name}.
|
59
53
|
MSG
|
60
54
|
end
|
61
55
|
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -171,7 +171,7 @@ dependencies:
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: 1.5.0
|
173
173
|
description: Add support to complex resources of PostgreSQL, like data types, user-defined
|
174
|
-
types and
|
174
|
+
types and auxiliary statements (CTE)
|
175
175
|
email:
|
176
176
|
- carlinhus.fsilva@gmail.com
|
177
177
|
executables: []
|
@@ -185,7 +185,6 @@ files:
|
|
185
185
|
- lib/torque/postgresql/adapter.rb
|
186
186
|
- lib/torque/postgresql/adapter/database_statements.rb
|
187
187
|
- lib/torque/postgresql/adapter/oid.rb
|
188
|
-
- lib/torque/postgresql/adapter/oid/array.rb
|
189
188
|
- lib/torque/postgresql/adapter/oid/enum.rb
|
190
189
|
- lib/torque/postgresql/adapter/oid/interval.rb
|
191
190
|
- lib/torque/postgresql/adapter/quoting.rb
|
@@ -199,9 +198,11 @@ files:
|
|
199
198
|
- lib/torque/postgresql/attributes/lazy.rb
|
200
199
|
- lib/torque/postgresql/attributes/type_map.rb
|
201
200
|
- lib/torque/postgresql/auxiliary_statement.rb
|
201
|
+
- lib/torque/postgresql/auxiliary_statement/settings.rb
|
202
202
|
- lib/torque/postgresql/base.rb
|
203
203
|
- lib/torque/postgresql/collector.rb
|
204
204
|
- lib/torque/postgresql/config.rb
|
205
|
+
- lib/torque/postgresql/i18n.rb
|
205
206
|
- lib/torque/postgresql/migration.rb
|
206
207
|
- lib/torque/postgresql/migration/command_recorder.rb
|
207
208
|
- lib/torque/postgresql/relation.rb
|
@@ -221,16 +222,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
221
222
|
requirements:
|
222
223
|
- - ">="
|
223
224
|
- !ruby/object:Gem::Version
|
224
|
-
version:
|
225
|
+
version: 2.2.2
|
225
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
227
|
requirements:
|
227
228
|
- - ">="
|
228
229
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
230
|
+
version: 1.8.11
|
230
231
|
requirements: []
|
231
232
|
rubyforge_project:
|
232
233
|
rubygems_version: 2.5.1
|
233
234
|
signing_key:
|
234
235
|
specification_version: 4
|
235
|
-
summary: ActiveRecord extension to
|
236
|
+
summary: ActiveRecord extension to access PostgreSQL advanced resources
|
236
237
|
test_files: []
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Torque
|
2
|
-
module PostgreSQL
|
3
|
-
module Adapter
|
4
|
-
module OID
|
5
|
-
module Array
|
6
|
-
|
7
|
-
def initialize(subtype, delimiter = ',')
|
8
|
-
super
|
9
|
-
@pg_encoder = Coder
|
10
|
-
@pg_decoder = Coder
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.prepend Array
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|