chicagowarehouse 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Rakefile +1 -1
- data/chicagowarehouse.gemspec +9 -6
- data/lib/chicago/database/schema_generator.rb +7 -7
- data/lib/chicago/schema/query_column.rb +3 -3
- data/spec/database/schema_generator_spec.rb +2 -2
- data/spec/query_spec.rb +92 -49
- data/spec/schema/query_column_spec.rb +3 -3
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617a93de9123548ce062b11bc4cb19ece4848d9b
|
4
|
+
data.tar.gz: a643b9eca3d49d7fbdd41649f0715450161cf6d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 034cada83703a2ba05965314f0e7fd27cac1f341e87dbe5b5b5ced687b270ce27c86b02caa2cdec565b074ea6b1fd5e7b7f854aa95d355c6407cee87eb325f81
|
7
|
+
data.tar.gz: 0ff262a34d32e4c80c99706ad6036370b3ca356d1a360c8fbe865c68baa69dcd2e33756a20b58b18eedf803a8855761a6903b63a61e1509e0da7b1fbb868561a
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -14,7 +14,7 @@ require 'rake'
|
|
14
14
|
require 'jeweler'
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
gem.name = "chicagowarehouse"
|
17
|
-
gem.version = "0.6.
|
17
|
+
gem.version = "0.6.8"
|
18
18
|
gem.summary = "Ruby Data Warehousing"
|
19
19
|
gem.description = "Simple Data Warehouse toolkit for ruby"
|
20
20
|
gem.author = "Roland Swingler"
|
data/chicagowarehouse.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: chicagowarehouse 0.6.
|
5
|
+
# stub: chicagowarehouse 0.6.8 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "chicagowarehouse"
|
9
|
-
s.version = "0.6.
|
9
|
+
s.version = "0.6.8"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Roland Swingler"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-05-06"
|
15
15
|
s.description = "Simple Data Warehouse toolkit for ruby"
|
16
16
|
s.email = "roland.swingler@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -91,10 +91,11 @@ Gem::Specification.new do |s|
|
|
91
91
|
s.specification_version = 4
|
92
92
|
|
93
93
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
94
|
-
s.add_runtime_dependency(%q<sequel>, [">= 4.
|
94
|
+
s.add_runtime_dependency(%q<sequel>, [">= 4.11"])
|
95
95
|
s.add_runtime_dependency(%q<sequel_migration_builder>, [">= 0.4.3"])
|
96
96
|
s.add_runtime_dependency(%q<chronic>, [">= 0"])
|
97
97
|
s.add_development_dependency(%q<mysql2>, [">= 0"])
|
98
|
+
s.add_development_dependency(%q<pg>, [">= 0"])
|
98
99
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
99
100
|
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
100
101
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
@@ -103,10 +104,11 @@ Gem::Specification.new do |s|
|
|
103
104
|
s.add_development_dependency(%q<flog>, [">= 0"])
|
104
105
|
s.add_development_dependency(%q<timecop>, [">= 0"])
|
105
106
|
else
|
106
|
-
s.add_dependency(%q<sequel>, [">= 4.
|
107
|
+
s.add_dependency(%q<sequel>, [">= 4.11"])
|
107
108
|
s.add_dependency(%q<sequel_migration_builder>, [">= 0.4.3"])
|
108
109
|
s.add_dependency(%q<chronic>, [">= 0"])
|
109
110
|
s.add_dependency(%q<mysql2>, [">= 0"])
|
111
|
+
s.add_dependency(%q<pg>, [">= 0"])
|
110
112
|
s.add_dependency(%q<yard>, [">= 0"])
|
111
113
|
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
112
114
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -116,10 +118,11 @@ Gem::Specification.new do |s|
|
|
116
118
|
s.add_dependency(%q<timecop>, [">= 0"])
|
117
119
|
end
|
118
120
|
else
|
119
|
-
s.add_dependency(%q<sequel>, [">= 4.
|
121
|
+
s.add_dependency(%q<sequel>, [">= 4.11"])
|
120
122
|
s.add_dependency(%q<sequel_migration_builder>, [">= 0.4.3"])
|
121
123
|
s.add_dependency(%q<chronic>, [">= 0"])
|
122
124
|
s.add_dependency(%q<mysql2>, [">= 0"])
|
125
|
+
s.add_dependency(%q<pg>, [">= 0"])
|
123
126
|
s.add_dependency(%q<yard>, [">= 0"])
|
124
127
|
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
125
128
|
s.add_dependency(%q<bundler>, [">= 0"])
|
@@ -3,10 +3,10 @@ module Chicago
|
|
3
3
|
# A StarSchema Visitor which produces a hash similar to the hash
|
4
4
|
# produced by Sequel.
|
5
5
|
class SchemaGenerator
|
6
|
-
attr_writer :
|
6
|
+
attr_writer :database_strategy
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
8
|
+
def initialize(database_strategy, generate_key_tables=true)
|
9
|
+
@database_strategy = database_strategy
|
10
10
|
@generate_key_tables = generate_key_tables
|
11
11
|
end
|
12
12
|
|
@@ -29,7 +29,7 @@ module Chicago
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def visit_column(column)
|
32
|
-
@
|
32
|
+
@database_strategy.column_hash(column)
|
33
33
|
end
|
34
34
|
|
35
35
|
alias :visit_measure :visit_column
|
@@ -40,9 +40,9 @@ module Chicago
|
|
40
40
|
def basic_table(table)
|
41
41
|
t = {
|
42
42
|
:primary_key => [:id],
|
43
|
-
:table_options => @
|
44
|
-
:indexes => @
|
45
|
-
:columns => [@
|
43
|
+
:table_options => @database_strategy.table_options,
|
44
|
+
:indexes => @database_strategy.indexes(table),
|
45
|
+
:columns => [@database_strategy.id_column]
|
46
46
|
}
|
47
47
|
|
48
48
|
t[:columns] += table.columns.reject(&:calculated?).
|
@@ -92,7 +92,7 @@ module Chicago
|
|
92
92
|
super
|
93
93
|
@select_name = @column.name.qualify(@owner.name)
|
94
94
|
@count_name = @owner.original_key.name.qualify(@owner.name)
|
95
|
-
@group_name = @
|
95
|
+
@group_name = @column.name.qualify(@owner.name)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -223,11 +223,11 @@ module Chicago
|
|
223
223
|
end
|
224
224
|
|
225
225
|
def select_name
|
226
|
-
|
226
|
+
Sequel.case([[{@pivoted_column.select_name => @value}, @column.select_name]], @unit)
|
227
227
|
end
|
228
228
|
|
229
229
|
def count_name
|
230
|
-
|
230
|
+
Sequel.case([[{@pivoted_column.select_name => @value}, @column.count_name]], @unit)
|
231
231
|
end
|
232
232
|
end
|
233
233
|
end
|
@@ -41,7 +41,7 @@ describe Chicago::Database::SchemaGenerator do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should have a table type of MyISAM for mysql" do
|
44
|
-
subject.
|
44
|
+
subject.database_strategy = Chicago::Database::MysqlStrategy.new
|
45
45
|
subject.visit_fact(@fact)[:facts_sales][:table_options].should == {:engine => "myisam"}
|
46
46
|
end
|
47
47
|
|
@@ -108,7 +108,7 @@ describe Chicago::Database::SchemaGenerator do
|
|
108
108
|
|
109
109
|
it "should have a table type of MyISAM for mysql" do
|
110
110
|
@dimension = @schema.define_dimension(:user)
|
111
|
-
subject.
|
111
|
+
subject.database_strategy = Chicago::Database::MysqlStrategy.new
|
112
112
|
subject.visit_dimension(@dimension)[:dimension_user][:table_options].should == {:engine => "myisam"}
|
113
113
|
end
|
114
114
|
|
data/spec/query_spec.rb
CHANGED
@@ -101,7 +101,8 @@ describe Chicago::Query do
|
|
101
101
|
|
102
102
|
it "selects a count" do
|
103
103
|
@q.select({:column => "product", :op => "count"})
|
104
|
-
@q.dataset.
|
104
|
+
@q.dataset.opts[:select].
|
105
|
+
should == [:count.sql_function(:original_id.qualify(:product)).distinct.as("product.count".to_sym)]
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
@@ -125,7 +126,7 @@ describe Chicago::Query do
|
|
125
126
|
end
|
126
127
|
|
127
128
|
it "selects from the correctly aliased table" do
|
128
|
-
@q.dataset.sql.should
|
129
|
+
@q.dataset.sql.should == TEST_DB[:facts_sales.as(:sales)].sql
|
129
130
|
end
|
130
131
|
|
131
132
|
it "selects a qualified column" do
|
@@ -194,7 +195,8 @@ describe Chicago::Query do
|
|
194
195
|
|
195
196
|
it "selects an explicit distinct count, via a dimension reference" do
|
196
197
|
@q.select({:column => "sales.product.type", :op => "count"})
|
197
|
-
@q.dataset.
|
198
|
+
@q.dataset.opts[:select].
|
199
|
+
should == [:count.sql_function(:type.qualify(:product)).distinct.as("sales.product.type.count".to_sym)]
|
198
200
|
end
|
199
201
|
|
200
202
|
it "selects the main identifier for a bare dimension" do
|
@@ -205,7 +207,8 @@ describe Chicago::Query do
|
|
205
207
|
|
206
208
|
it "selects the count of a dimension" do
|
207
209
|
@q.select({:column => "sales.product", :op => "count"})
|
208
|
-
@q.dataset.
|
210
|
+
@q.dataset.opts[:select].
|
211
|
+
should == [:count.sql_function(:original_id.qualify(:product)).distinct.as("sales.product.count".to_sym)]
|
209
212
|
end
|
210
213
|
|
211
214
|
describe "pivots columns" do
|
@@ -217,13 +220,13 @@ describe Chicago::Query do
|
|
217
220
|
}.to raise_error(Chicago::UnimplementedError)
|
218
221
|
end
|
219
222
|
|
220
|
-
it "via
|
223
|
+
it "via CASE, for a measure, by a boolean column" do
|
221
224
|
@q.select({ :column => "sales.total",
|
222
225
|
:op => "sum",
|
223
226
|
:pivot => "sales.product.flag"})
|
224
227
|
@q.dataset.opts[:select].
|
225
|
-
should == [:sum.sql_function(
|
226
|
-
:sum.sql_function(
|
228
|
+
should == [:sum.sql_function(Sequel.case([[{:flag.qualify(:product) => true}, :total.qualify(:sales)]], 0)).as("sales.total:sales.product.flag.0.sum".to_sym),
|
229
|
+
:sum.sql_function(Sequel.case([[{:flag.qualify(:product) => false}, :total.qualify(:sales)]], 0)).as("sales.total:sales.product.flag.1.sum".to_sym)
|
227
230
|
]
|
228
231
|
end
|
229
232
|
|
@@ -240,8 +243,8 @@ describe Chicago::Query do
|
|
240
243
|
:op => "avg",
|
241
244
|
:pivot => "sales.product.flag"})
|
242
245
|
@q.dataset.opts[:select].
|
243
|
-
should == [:avg.sql_function(
|
244
|
-
:avg.sql_function(
|
246
|
+
should == [:avg.sql_function(Sequel.case([[{:flag.qualify(:product) => true}, :total.qualify(:sales)]], nil)).as("sales.total:sales.product.flag.0.avg".to_sym),
|
247
|
+
:avg.sql_function(Sequel.case([[{:flag.qualify(:product) => false}, :total.qualify(:sales)]], nil)).as("sales.total:sales.product.flag.1.avg".to_sym)
|
245
248
|
]
|
246
249
|
end
|
247
250
|
|
@@ -249,18 +252,20 @@ describe Chicago::Query do
|
|
249
252
|
@q.select({ :column => "sales.product",
|
250
253
|
:op => "count",
|
251
254
|
:pivot => "sales.product.flag"})
|
252
|
-
@q.dataset.
|
253
|
-
|
255
|
+
@q.dataset.opts[:select].
|
256
|
+
should == [:count.sql_function(Sequel.case([[{:flag.qualify(:product) => true}, :original_id.qualify(:product)]], nil)).distinct.as("sales.product:sales.product.flag.0.count".to_sym),
|
257
|
+
:count.sql_function(Sequel.case([[{:flag.qualify(:product) => false}, :original_id.qualify(:product)]], nil)).distinct.as("sales.product:sales.product.flag.1.count".to_sym)
|
258
|
+
]
|
254
259
|
end
|
255
260
|
|
256
|
-
it "should generate SQL pivots, via
|
261
|
+
it "should generate SQL pivots, via CASE, for a measure, by a bounded integer" do
|
257
262
|
@q.select({ :column => "sales.total",
|
258
263
|
:op => "sum",
|
259
264
|
:pivot => "sales.product.rating"})
|
260
265
|
@q.dataset.opts[:select].size.should == 10
|
261
266
|
end
|
262
267
|
|
263
|
-
it "should generate SQL pivots, via
|
268
|
+
it "should generate SQL pivots, via CASE, for a measure, by a string with elements" do
|
264
269
|
@q.select({ :column => "sales.total",
|
265
270
|
:op => "sum",
|
266
271
|
:pivot => "sales.product.sale"})
|
@@ -271,14 +276,28 @@ describe Chicago::Query do
|
|
271
276
|
@q.select({ :column => "sales.total",
|
272
277
|
:op => "sum",
|
273
278
|
:pivot => "sales.product.sale"})
|
274
|
-
@q.dataset.
|
279
|
+
@q.dataset.opts[:join].
|
280
|
+
should == [Sequel::SQL::JoinOnClause.new(
|
281
|
+
Sequel.expr(Sequel.qualify("product","id") => :product_dimension_id.qualify(:sales)),
|
282
|
+
:inner,
|
283
|
+
:dimension_product.as(:product))]
|
275
284
|
end
|
276
285
|
|
277
286
|
it "should join on the counted table when pivoting" do
|
278
287
|
@q.select({ :column => "sales.product",
|
279
288
|
:op => "count",
|
280
289
|
:pivot => "sales.buyer.recent"})
|
281
|
-
|
290
|
+
|
291
|
+
@q.dataset.opts[:join].
|
292
|
+
should == [
|
293
|
+
Sequel::SQL::JoinOnClause.new(
|
294
|
+
Sequel.expr(Sequel.qualify("buyer","id") => :buyer_dimension_id.qualify(:sales)),
|
295
|
+
:inner,
|
296
|
+
:dimension_customer.as(:buyer)),
|
297
|
+
Sequel::SQL::JoinOnClause.new(
|
298
|
+
Sequel.expr(Sequel.qualify("product","id") => :product_dimension_id.qualify(:sales)),
|
299
|
+
:inner,
|
300
|
+
:dimension_product.as(:product))]
|
282
301
|
end
|
283
302
|
|
284
303
|
it "should not group on pivoted columns" do
|
@@ -299,11 +318,6 @@ describe Chicago::Query do
|
|
299
318
|
@q.dataset.opts[:group].should == ['sales.product.manufacturer'.to_sym]
|
300
319
|
end
|
301
320
|
|
302
|
-
it "groups on the original key instead of a main identifier column" do
|
303
|
-
@q.select 'sales.product.name'
|
304
|
-
@q.dataset.opts[:group].should == [:original_id.qualify(:product)]
|
305
|
-
end
|
306
|
-
|
307
321
|
it "doesn't group on calculated columns" do
|
308
322
|
@q.select :column =>'sales.total', :op => 'sum'
|
309
323
|
@q.dataset.opts[:group].should be_nil
|
@@ -321,20 +335,29 @@ describe Chicago::Query do
|
|
321
335
|
|
322
336
|
it "joins on the dimension table if selecting from the dimension" do
|
323
337
|
@q.select("sales.order_ref", "sales.product.name")
|
324
|
-
@q.dataset.
|
325
|
-
should
|
338
|
+
@q.dataset.opts[:join].
|
339
|
+
should == [Sequel::SQL::JoinOnClause.new(
|
340
|
+
Sequel.expr(Sequel.qualify("product","id") => :product_dimension_id.qualify(:sales)),
|
341
|
+
:inner,
|
342
|
+
:dimension_product.as(:product))]
|
326
343
|
end
|
327
344
|
|
328
345
|
it "joins on a roleplayed dimension table if selecting from the dimension" do
|
329
346
|
@q.select("sales.order_ref", "sales.seller.name")
|
330
|
-
@q.dataset.
|
331
|
-
should
|
347
|
+
@q.dataset.opts[:join].
|
348
|
+
should == [Sequel::SQL::JoinOnClause.new(
|
349
|
+
Sequel.expr(Sequel.qualify("seller","id") => :seller_dimension_id.qualify(:sales)),
|
350
|
+
:inner,
|
351
|
+
:dimension_customer.as(:seller))]
|
332
352
|
end
|
333
353
|
|
334
354
|
it "joins when counting dimensions" do
|
335
355
|
@q.select({:column => "sales.product", :op => "count"})
|
336
|
-
@q.dataset.
|
337
|
-
should
|
356
|
+
@q.dataset.opts[:join].
|
357
|
+
should == [Sequel::SQL::JoinOnClause.new(
|
358
|
+
Sequel.expr(Sequel.qualify("product","id") => :product_dimension_id.qualify(:sales)),
|
359
|
+
:inner,
|
360
|
+
:dimension_product.as(:product))]
|
338
361
|
end
|
339
362
|
|
340
363
|
it "joins on multiple tables" do
|
@@ -393,72 +416,92 @@ describe Chicago::Query do
|
|
393
416
|
end
|
394
417
|
|
395
418
|
it "joins a filter dimension" do
|
396
|
-
@q.filter({:column => "sales.product.sku", :value => "123", :op => :eq}).dataset.
|
397
|
-
should
|
419
|
+
@q.filter({:column => "sales.product.sku", :value => "123", :op => :eq}).dataset.opts[:join].
|
420
|
+
should == [Sequel::SQL::JoinOnClause.new(
|
421
|
+
Sequel.expr(Sequel.qualify("product","id") => :product_dimension_id.qualify(:sales)),
|
422
|
+
:inner,
|
423
|
+
:dimension_product.as(:product))]
|
398
424
|
end
|
399
425
|
|
400
426
|
it "can filter based on greater than" do
|
401
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gt}).dataset.
|
427
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gt}).dataset.opts[:where].
|
428
|
+
should == Sequel.expr(:rating.qualify(:product) > 2)
|
402
429
|
end
|
403
430
|
|
404
431
|
it "can filter based on greater than or equal" do
|
405
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gte}).dataset.
|
432
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gte}).dataset.opts[:where].
|
433
|
+
should == Sequel.expr(:rating.qualify(:product) >= 2)
|
406
434
|
end
|
407
435
|
|
408
436
|
it "can filter based on less than" do
|
409
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :lt}).dataset.
|
437
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :lt}).dataset.opts[:where].
|
438
|
+
should == Sequel.expr(:rating.qualify(:product) < 2)
|
410
439
|
end
|
411
440
|
|
412
441
|
it "can filter based on less than or equal" do
|
413
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :lte}).dataset.
|
442
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :lte}).dataset.opts[:where].
|
443
|
+
should == Sequel.expr(:rating.qualify(:product) <= 2)
|
414
444
|
end
|
415
445
|
|
416
446
|
it "can filter multiple integers" do
|
417
|
-
@q.filter({:column => "sales.product.rating", :value => ["1", "2"], :op => :eq}).dataset.
|
447
|
+
@q.filter({:column => "sales.product.rating", :value => ["1", "2"], :op => :eq}).dataset.opts[:where].
|
448
|
+
should == Sequel.expr(:rating.qualify(:product) => [1, 2])
|
418
449
|
end
|
419
450
|
|
420
451
|
it "can filter based on not equal" do
|
421
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :ne}).dataset.
|
452
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :ne}).dataset.opts[:where].
|
453
|
+
should == Sequel.~(Sequel.expr(:rating.qualify(:product) => 2))
|
422
454
|
end
|
423
455
|
|
424
456
|
it "can filter based on 2 comparisons" do
|
425
|
-
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gte}, {:column => "sales.product.rating", :value => "7", :op => :lt}).dataset.
|
457
|
+
@q.filter({:column => "sales.product.rating", :value => "2", :op => :gte}, {:column => "sales.product.rating", :value => "7", :op => :lt}).dataset.opts[:where].
|
458
|
+
should == Sequel.&(Sequel.expr(:rating.qualify(:product) >= 2),Sequel.expr(:rating.qualify(:product) < 7))
|
426
459
|
end
|
427
460
|
|
428
461
|
it "can filter dates" do
|
429
|
-
@q.filter({:column => "sales.product.date", :value => "01/02/12", :op => :eq}).dataset.
|
462
|
+
@q.filter({:column => "sales.product.date", :value => "01/02/12", :op => :eq}).dataset.opts[:where].
|
463
|
+
should == Sequel.expr(:date.qualify(:product) => Date.new(year=2012,month=2,day=1))
|
430
464
|
end
|
431
465
|
|
432
466
|
it "can filter based on starts with" do
|
433
|
-
@q.filter({:column => "sales.product.sku", :value => "123", :op => :sw}).dataset.
|
467
|
+
@q.filter({:column => "sales.product.sku", :value => "123", :op => :sw}).dataset.opts[:where].
|
468
|
+
should == Sequel.ilike(:sku.qualify(:product), "123%")
|
434
469
|
end
|
435
470
|
|
436
471
|
it "can filter based on 'starts with' with multiple values" do
|
437
|
-
@q.filter({:column => "sales.product.sku", :value => ["123","AB"], :op => :sw}).dataset.
|
472
|
+
@q.filter({:column => "sales.product.sku", :value => ["123","AB"], :op => :sw}).dataset.opts[:where].
|
473
|
+
should == Sequel.|(Sequel.ilike(:sku.qualify(:product), "123%"), Sequel.ilike(:sku.qualify(:product), "AB%"))
|
474
|
+
|
438
475
|
end
|
439
476
|
|
440
477
|
it "can filter based on not starts with" do
|
441
|
-
@q.filter({:column => "sales.product.sku", :value => "123", :op => :nsw}).dataset.
|
478
|
+
@q.filter({:column => "sales.product.sku", :value => "123", :op => :nsw}).dataset.opts[:where].
|
479
|
+
should == Sequel.~(Sequel.ilike(:sku.qualify(:product), "123%"))
|
442
480
|
end
|
443
481
|
|
444
482
|
it "can filter based on 'not starts with' with multiple values" do
|
445
|
-
@q.filter({:column => "sales.product.sku", :value => ["123","AB"], :op => :nsw}).dataset.
|
483
|
+
@q.filter({:column => "sales.product.sku", :value => ["123","AB"], :op => :nsw}).dataset.opts[:where].
|
484
|
+
should == Sequel.&(Sequel.~(Sequel.ilike(:sku.qualify(:product), "123%")), Sequel.~(Sequel.ilike(:sku.qualify(:product), "AB%")))
|
446
485
|
end
|
447
486
|
|
448
487
|
it "can filter based on contains" do
|
449
|
-
@q.filter({:column => "sales.product.sku", :value => "123", :op => :con}).dataset.
|
488
|
+
@q.filter({:column => "sales.product.sku", :value => "123", :op => :con}).dataset.opts[:where].
|
489
|
+
should == Sequel.ilike(:sku.qualify(:product), "%123%")
|
450
490
|
end
|
451
491
|
|
452
492
|
it "can filter based on not contains" do
|
453
|
-
@q.filter({:column => "sales.product.sku", :value => "123", :op => :ncon}).dataset.
|
493
|
+
@q.filter({:column => "sales.product.sku", :value => "123", :op => :ncon}).dataset.opts[:where].
|
494
|
+
should == Sequel.~(Sequel.ilike(:sku.qualify(:product), "%123%"))
|
454
495
|
end
|
455
496
|
|
456
497
|
it "can filter based on multiple contains" do
|
457
|
-
@q.filter({:column => "sales.product.sku", :value => ["123", "AB", "foo"], :op => :con}).dataset.
|
498
|
+
@q.filter({:column => "sales.product.sku", :value => ["123", "AB", "foo"], :op => :con}).dataset.opts[:where].
|
499
|
+
should == Sequel.|(Sequel.ilike(:sku.qualify(:product), "%123%"), Sequel.ilike(:sku.qualify(:product), "%AB%"), Sequel.ilike(:sku.qualify(:product), "%foo%"))
|
458
500
|
end
|
459
501
|
|
460
|
-
it "can filter based on multiple contains" do
|
461
|
-
@q.filter({:column => "sales.product.sku", :value => ["123", "AB", "foo"], :op => :ncon}).dataset.
|
502
|
+
it "can filter based on multiple not contains" do
|
503
|
+
@q.filter({:column => "sales.product.sku", :value => ["123", "AB", "foo"], :op => :ncon}).dataset.opts[:where].
|
504
|
+
should == Sequel.&(Sequel.~(Sequel.ilike(:sku.qualify(:product), "%123%")), Sequel.~(Sequel.ilike(:sku.qualify(:product), "%AB%")), Sequel.~(Sequel.ilike(:sku.qualify(:product), "%foo%")))
|
462
505
|
end
|
463
506
|
|
464
507
|
it "does not join the base table when filtering" do
|
@@ -467,13 +510,13 @@ describe Chicago::Query do
|
|
467
510
|
end
|
468
511
|
|
469
512
|
it "filters in the having clause when a calculated column is filtered" do
|
470
|
-
@q.filter({:column => {:column => "sales.total", :op => "sum"}, :value => 2, :op => :eq}).dataset.
|
471
|
-
|
513
|
+
@q.filter({:column => {:column => "sales.total", :op => "sum"}, :value => 2, :op => :eq}).dataset.opts[:having].
|
514
|
+
should == Sequel.expr(:sum.sql_function(:total.qualify(:sales)) => 2)
|
472
515
|
end
|
473
516
|
|
474
517
|
it "filters in the having clause when a virtual calculated column is filtered" do
|
475
|
-
@q.filter({:column => "sales.vat", :value => 2, :op => :gte}).dataset.
|
476
|
-
|
518
|
+
@q.filter({:column => "sales.vat", :value => 2, :op => :gte}).dataset.opts[:having].
|
519
|
+
should == Sequel.expr(Sequel.*(:sum.sql_function(:total),:vat_rate) >= 2)
|
477
520
|
end
|
478
521
|
|
479
522
|
describe "#columns" do
|
@@ -134,12 +134,12 @@ describe Chicago::Schema::QueryColumn do
|
|
134
134
|
subject.select_name.should == :bar.qualify(:foo)
|
135
135
|
end
|
136
136
|
|
137
|
-
it "uses the
|
137
|
+
it "uses the original_id in COUNT" do
|
138
138
|
subject.count_name.should == :original_id.qualify(:foo)
|
139
139
|
end
|
140
140
|
|
141
|
-
it "uses the
|
142
|
-
subject.group_name.should == :
|
141
|
+
it "uses the column name in GROUP BY" do
|
142
|
+
subject.group_name.should == :bar.qualify(:foo)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "delegates label to the decorated column" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chicagowarehouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roland Swingler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '4.
|
19
|
+
version: '4.11'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '4.
|
26
|
+
version: '4.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel_migration_builder
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: yard
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|