smql 0.0.4 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/smql_to_ar/condition_types.rb +7 -9
- data/lib/smql_to_ar/query_builder.rb +7 -9
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.4
|
1
|
+
0.0.4.1
|
@@ -159,12 +159,13 @@ class SmqlToAR
|
|
159
159
|
builder.where values.keys.collect {|vid| self.class::Where % [ col, vid.to_s ] }
|
160
160
|
end
|
161
161
|
else
|
162
|
+
b2 = SmqlToAR::And.new builder
|
162
163
|
values.keys.each do |vid|
|
163
|
-
|
164
|
+
b2.where SmqlToAR::Or[ *@cols.collect {|col|
|
164
165
|
col.joins builder, table
|
165
166
|
col = builder.column table+col.path, col.col
|
166
167
|
self.class::Where % [ col, vid.to_s ]
|
167
|
-
}
|
168
|
+
}]
|
168
169
|
end
|
169
170
|
end
|
170
171
|
self
|
@@ -229,7 +230,6 @@ class SmqlToAR
|
|
229
230
|
super( *pars)
|
230
231
|
@value = Array.wrap @value
|
231
232
|
cols = {}
|
232
|
-
p self: self, cols: @cols
|
233
233
|
@cols.each do |col|
|
234
234
|
col_model = col.relation
|
235
235
|
cols[col] = [col_model] + @value.collect {|val| ConditionTypes.try_parse( col_model, val) }
|
@@ -250,7 +250,6 @@ class SmqlToAR
|
|
250
250
|
b2 = 1 == sub.length ? builder : Or.new( builder)
|
251
251
|
sub.each {|i| i.collect( &it.build( And.new( b2), t)); p 'or' => b2 }
|
252
252
|
end
|
253
|
-
ap '=>' => builder
|
254
253
|
self
|
255
254
|
end
|
256
255
|
end
|
@@ -274,7 +273,7 @@ class SmqlToAR
|
|
274
273
|
def initialize model, cols, val
|
275
274
|
super model, cols, val[1]
|
276
275
|
# sub: model, subquery, sub(condition)
|
277
|
-
@cols.each {|col, sub| sub[ 1
|
276
|
+
@cols.each {|col, sub| sub[ 1..-1] = SmqlToAR.new( col.relation, val[0]).parse, *sub[-1] }
|
278
277
|
end
|
279
278
|
|
280
279
|
def verify_column col
|
@@ -285,6 +284,7 @@ class SmqlToAR
|
|
285
284
|
@cols.each do |col, sub|
|
286
285
|
t = table+col.to_a
|
287
286
|
builder.sub_joins t, col, *sub[0..1]
|
287
|
+
#ap sub: sub[2..-1]
|
288
288
|
sub[2..-1].each &it.build( builder, t)
|
289
289
|
end
|
290
290
|
self
|
@@ -336,7 +336,6 @@ class SmqlToAR
|
|
336
336
|
|
337
337
|
class <<self
|
338
338
|
def try_parse model, func, args
|
339
|
-
SmqlToAR.logger.info( { try_parse: [func,args]}.inspect)
|
340
339
|
self.new model, func, args if self::Name === func and self::Expected.any?( &it === args)
|
341
340
|
end
|
342
341
|
|
@@ -389,7 +388,7 @@ class SmqlToAR
|
|
389
388
|
|
390
389
|
def build builder, table
|
391
390
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
392
|
-
builder.limit @args
|
391
|
+
builder.limit = Array.wrap(@args).first.to_i
|
393
392
|
end
|
394
393
|
end
|
395
394
|
|
@@ -399,12 +398,11 @@ class SmqlToAR
|
|
399
398
|
|
400
399
|
def build builder, table
|
401
400
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
402
|
-
builder.offset @args
|
401
|
+
builder.offset = Array.wrap(@args).first.to_i
|
403
402
|
end
|
404
403
|
end
|
405
404
|
|
406
405
|
def self.new model, col, val
|
407
|
-
SmqlToAR.logger.info( { function: col.first.to_sym }.inspect)
|
408
406
|
r = nil
|
409
407
|
constants.each do |c|
|
410
408
|
next if [:Function, :Where, :Expected, :Operator].include? c
|
@@ -79,7 +79,7 @@ class SmqlToAR
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def build_join orig, pretable, table, prekey, key
|
82
|
-
" LEFT
|
82
|
+
" LEFT JOIN #{orig} AS #{quote_table_name table} ON #{column pretable, prekey} = #{column table, key} "
|
83
83
|
end
|
84
84
|
|
85
85
|
def sub_joins table, col, model, query
|
@@ -142,13 +142,12 @@ class SmqlToAR
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def build_ar
|
145
|
-
where_str = @_where.type_correction!.optimize!.
|
145
|
+
where_str = @_where.type_correction!.optimize!.build_where
|
146
146
|
incls = {}
|
147
147
|
@_includes.each do |inc|
|
148
148
|
b = incls
|
149
149
|
inc[1..-1].collect {|rel| b = b[rel] ||= {} }
|
150
150
|
end
|
151
|
-
@logger.info where: where_str, wobs: @_wobs
|
152
151
|
@model = @model.
|
153
152
|
select( @_select.join( ', ')).
|
154
153
|
joins( @_joins).
|
@@ -182,7 +181,6 @@ class SmqlToAR
|
|
182
181
|
delegate :wobs, :joins, :includes, :sub_joins, :vid, :quote_column_name, :quoter, :quote_table_name, :column, :to => :parent
|
183
182
|
|
184
183
|
def initialize parent, tmp = false
|
185
|
-
p init: self, parent: parent
|
186
184
|
@parent = parent
|
187
185
|
@parent.where self unless @parend.nil? && tmp
|
188
186
|
end
|
@@ -207,7 +205,6 @@ class SmqlToAR
|
|
207
205
|
end
|
208
206
|
|
209
207
|
def optimize!
|
210
|
-
p optimize: self
|
211
208
|
ext = []
|
212
209
|
collect! do |sub|
|
213
210
|
sub = sub.optimize! if sub.kind_of? Array
|
@@ -220,8 +217,6 @@ class SmqlToAR
|
|
220
217
|
sub
|
221
218
|
end
|
222
219
|
end.compact!
|
223
|
-
p optimized: self
|
224
|
-
p ext: ext
|
225
220
|
push *ext
|
226
221
|
self
|
227
222
|
end
|
@@ -231,18 +226,21 @@ class SmqlToAR
|
|
231
226
|
end
|
232
227
|
def default() SmqlToAR::And end
|
233
228
|
def default_new( parent) default.new self, parent, false end
|
229
|
+
def collect_build_where
|
230
|
+
collect {|x| x.respond_to?( :build_where) ? x.build_where : x.to_s }
|
231
|
+
end
|
234
232
|
end
|
235
233
|
|
236
234
|
class And < SubBuilder
|
237
235
|
def default; SmqlToAR::Or; end
|
238
236
|
def build_where
|
239
|
-
join ' AND '
|
237
|
+
collect_build_where.join ' AND '
|
240
238
|
end
|
241
239
|
end
|
242
240
|
|
243
241
|
class Or < SubBuilder
|
244
242
|
def build_where
|
245
|
-
join ' OR '
|
243
|
+
collect_build_where.join ' OR '
|
246
244
|
end
|
247
245
|
end
|
248
246
|
end
|
metadata
CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.0.4.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Denis Knauf
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-06 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|