smql 0.0.5.1 → 0.0.5.2
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.
- data/VERSION +1 -1
- data/lib/smql_to_ar/condition_types.rb +24 -14
- data/lib/smql_to_ar/query_builder.rb +8 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.5.
|
1
|
+
0.0.5.2
|
@@ -153,7 +153,7 @@ class SmqlToAR
|
|
153
153
|
# 2) {"givenname=", ["Peter", "Hans"]} #=> ( givenname = 'Peter' OR givenname = 'Hans' )
|
154
154
|
# 3) {"givenname|surname=", ["Peter", "Mueller"]}
|
155
155
|
# #=> ( givenname = 'Peter' OR surname = 'Peter' ) AND ( givenname = 'Mueller' OR surname = 'Mueller' )
|
156
|
-
def
|
156
|
+
def condition_build builder, table
|
157
157
|
values = Hash[ @value.collect {|value| [ builder.vid, value ] } ]
|
158
158
|
values.each {|k, v| builder.wobs k.to_sym => v }
|
159
159
|
if 1 == @cols.length
|
@@ -174,6 +174,7 @@ class SmqlToAR
|
|
174
174
|
end
|
175
175
|
self
|
176
176
|
end
|
177
|
+
alias build condition_build
|
177
178
|
end
|
178
179
|
|
179
180
|
class NotInRange < Condition
|
@@ -190,7 +191,7 @@ class SmqlToAR
|
|
190
191
|
super model, cols, val
|
191
192
|
end
|
192
193
|
|
193
|
-
def
|
194
|
+
def not_in_range_build builder, table
|
194
195
|
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
195
196
|
@cols.each do |col|
|
196
197
|
col.joins builder, table
|
@@ -198,11 +199,12 @@ class SmqlToAR
|
|
198
199
|
end
|
199
200
|
self
|
200
201
|
end
|
202
|
+
alias build not_in_range_build
|
201
203
|
end
|
202
204
|
InRange = simple_condition NotInRange, '..', '%s BETWEEN %s AND %s'
|
203
205
|
|
204
|
-
class
|
205
|
-
Operator, Where = '
|
206
|
+
class Overlaps < Condition
|
207
|
+
Operator, Where = '<=>', '(%s, %s) OVERLAPS (%s, %s)'
|
206
208
|
Expected = [Range, lambda {|val|
|
207
209
|
Array === val && 2 == val.length &&
|
208
210
|
[Time, Date, String].any? {|v|v===val[0]} &&
|
@@ -225,7 +227,7 @@ class SmqlToAR
|
|
225
227
|
super model, cols, val
|
226
228
|
end
|
227
229
|
|
228
|
-
def
|
230
|
+
def overlaps_build builder, table
|
229
231
|
builder.wobs (v1 = builder.vid).to_sym => @value.begin, (v2 = builder.vid).to_sym => @value.end
|
230
232
|
v1 = "TIMESTAMP #{v1}"
|
231
233
|
v2 = "TIMESTAMP #{v2}"
|
@@ -236,15 +238,16 @@ class SmqlToAR
|
|
236
238
|
builder.column( table+f.path, f.col), builder.column( table+s.path, s.col), v1, v2]
|
237
239
|
end
|
238
240
|
end
|
241
|
+
alias build overlaps_build
|
239
242
|
end
|
240
|
-
|
243
|
+
NotOverlaps = simple_condition Overlaps, '<=>', 'NOT (%s, %s) OVERLAPS (%s, %s)'
|
241
244
|
|
242
245
|
class NotIn < Condition
|
243
246
|
Operator = '!|='
|
244
247
|
Where = "%s NOT IN (%s)"
|
245
248
|
Expected = [Array]
|
246
249
|
|
247
|
-
def
|
250
|
+
def not_in_build builder, table
|
248
251
|
builder.wobs (v = builder.vid).to_sym => @value
|
249
252
|
@cols.each do |col|
|
250
253
|
col.joins builder, table
|
@@ -252,6 +255,7 @@ class SmqlToAR
|
|
252
255
|
end
|
253
256
|
self
|
254
257
|
end
|
258
|
+
alias build not_in_build
|
255
259
|
end
|
256
260
|
|
257
261
|
In = simple_condition NotIn, '|=', '%s IN (%s)', [Array]
|
@@ -290,7 +294,7 @@ class SmqlToAR
|
|
290
294
|
raise_unless col.relation, NonExistingRelationError.new( %w[Relation], col)
|
291
295
|
end
|
292
296
|
|
293
|
-
def
|
297
|
+
def equal_join_build builder, table
|
294
298
|
if 2 < @cols.first.second.length
|
295
299
|
b2, b3 = And, Or
|
296
300
|
else
|
@@ -300,7 +304,7 @@ class SmqlToAR
|
|
300
304
|
@cols.each do |col, sub|
|
301
305
|
model, *sub = sub
|
302
306
|
t = table + col.path + [col.col]
|
303
|
-
col.joins
|
307
|
+
col.joins builder, table
|
304
308
|
builder.joins t, model
|
305
309
|
b4 = b3.new( b2)
|
306
310
|
sub.each do |i|
|
@@ -310,6 +314,7 @@ class SmqlToAR
|
|
310
314
|
end
|
311
315
|
self
|
312
316
|
end
|
317
|
+
alias build equal_join_build
|
313
318
|
end
|
314
319
|
|
315
320
|
# Takes to Queries.
|
@@ -339,7 +344,7 @@ class SmqlToAR
|
|
339
344
|
raise_unless col.child?, ConColumnError.new( [:Column], col)
|
340
345
|
end
|
341
346
|
|
342
|
-
def
|
347
|
+
def sub_equal_join_build builder, table
|
343
348
|
@cols.each do |col, sub|
|
344
349
|
t = table+col.to_a
|
345
350
|
builder.sub_joins t, col, *sub[0..1]
|
@@ -348,6 +353,7 @@ class SmqlToAR
|
|
348
353
|
end
|
349
354
|
self
|
350
355
|
end
|
356
|
+
alias build sub_equal_join_build
|
351
357
|
end
|
352
358
|
=end
|
353
359
|
|
@@ -372,7 +378,7 @@ class SmqlToAR
|
|
372
378
|
raise_unless col.exist_in? || SmqlToAR.model_of( col.last_model, col.col), NonExistingSelectableError.new( col)
|
373
379
|
end
|
374
380
|
|
375
|
-
def
|
381
|
+
def select_build builder, table
|
376
382
|
@cols.each do |col|
|
377
383
|
if col.exist_in?
|
378
384
|
col.joins builder, table
|
@@ -384,6 +390,7 @@ class SmqlToAR
|
|
384
390
|
end
|
385
391
|
self
|
386
392
|
end
|
393
|
+
alias build select_build
|
387
394
|
end
|
388
395
|
|
389
396
|
class Functions < Condition
|
@@ -432,7 +439,7 @@ class SmqlToAR
|
|
432
439
|
super model, func, args
|
433
440
|
end
|
434
441
|
|
435
|
-
def
|
442
|
+
def order_build builder, table
|
436
443
|
return if @args.blank?
|
437
444
|
@args.each do |o|
|
438
445
|
col, o = o
|
@@ -442,26 +449,29 @@ class SmqlToAR
|
|
442
449
|
builder.order t, col.col, o
|
443
450
|
end
|
444
451
|
end
|
452
|
+
alias build order_build
|
445
453
|
end
|
446
454
|
|
447
455
|
class Limit < Function
|
448
456
|
Name = :limit
|
449
457
|
Expected = [Fixnum]
|
450
458
|
|
451
|
-
def
|
459
|
+
def limit_build builder, table
|
452
460
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
453
461
|
builder.limit = Array.wrap(@args).first.to_i
|
454
462
|
end
|
463
|
+
alias build limit_build
|
455
464
|
end
|
456
465
|
|
457
466
|
class Offset < Function
|
458
467
|
Name = :offset
|
459
468
|
Expected = [Fixnum]
|
460
469
|
|
461
|
-
def
|
470
|
+
def offset_build builder, table
|
462
471
|
raise_unless 1 == table.length, RootOnlyFunctionError.new( table)
|
463
472
|
builder.offset = Array.wrap(@args).first.to_i
|
464
473
|
end
|
474
|
+
alias build offset_build
|
465
475
|
end
|
466
476
|
|
467
477
|
def self.new model, col, val
|
@@ -135,25 +135,25 @@ class SmqlToAR
|
|
135
135
|
case refl
|
136
136
|
when ActiveRecord::Reflection::ThroughReflection
|
137
137
|
through = refl.through_reflection
|
138
|
-
|
139
|
-
srctable =
|
138
|
+
through_table = table[0...-1]+[Column::Col.new( through.name, table.last.as)]
|
139
|
+
srctable = through_table+[Column::Col.new( refl.source_reflection.name, table.last.as)]
|
140
140
|
@table_model[ srctable] = model
|
141
141
|
@table_alias[ table] = @table_alias[ srctable]
|
142
|
-
join_
|
143
|
-
join_ srctable, refl.klass, query,
|
142
|
+
join_ through_table, through.klass, quote_table_name( through.table_name)
|
143
|
+
join_ srctable, refl.klass, query, through_table
|
144
144
|
when ActiveRecord::Reflection::AssociationReflection
|
145
145
|
case refl.macro
|
146
146
|
when :has_many, :has_one
|
147
|
-
@_joins += build_join query, pretable, t, premodel.primary_key, refl.
|
147
|
+
@_joins += build_join query, pretable, t, premodel.primary_key, refl.foreign_key
|
148
148
|
when :belongs_to
|
149
|
-
@_joins += build_join query, pretable, t, refl.
|
149
|
+
@_joins += build_join query, pretable, t, refl.foreign_key, premodel.primary_key
|
150
150
|
when :has_and_belongs_to_many
|
151
151
|
jointable = [Column::Col.new(',')] + table
|
152
|
-
@_joins += build_join refl.options[:join_table], pretable, @table_alias[jointable], premodel.primary_key, refl.
|
152
|
+
@_joins += build_join refl.options[:join_table], pretable, @table_alias[ jointable], premodel.primary_key, refl.foreign_key
|
153
153
|
@_joins += build_join query, jointable, t, refl.association_foreign_key, refl.association_primary_key
|
154
154
|
else raise BuilderError, "Unkown reflection macro: #{refl.macro.inspect}"
|
155
155
|
end
|
156
|
-
else raise BuilderError, "Unkown reflection type: #{refl.class.name}"
|
156
|
+
else raise BuilderError, "Unkown reflection type: #{refl.class.name} #{refl.macro.inspect}"
|
157
157
|
end
|
158
158
|
self
|
159
159
|
end
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.0.5.
|
9
|
+
- 2
|
10
|
+
version: 0.0.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Denis Knauf
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|