groovy 0.4.0 → 0.4.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/example/basic.rb +3 -2
- data/example/relations.rb +1 -0
- data/lib/groovy/model.rb +5 -6
- data/lib/groovy/query.rb +4 -8
- data/lib/groovy/version.rb +1 -1
- data/spec/query_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b64b5151ebc9ad89b92fac064613d778e067449e11eb0c87cbf8ce40ca5e2630
|
4
|
+
data.tar.gz: 3e95ca4bac3946bcf79805c174216be0cb2870c06e47369056054bfb4d61a637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3320e1c8e3d31b9d48c2fbf409f2688b3be16734eebd631b9ee44f9509934968079b9ed1ab14a02422a559865e2619da1954640feed825bc17b8865ab96ac4d1
|
7
|
+
data.tar.gz: 1d1ebb476d22fa504a2b1f7ef7585f298fb5fbc84dbdc22cb34997c1a8e57032622e0c12867aab730bf75f08293d7f093a49059efb68d11c150be5684e4c9c34
|
data/example/basic.rb
CHANGED
@@ -9,6 +9,7 @@ class Product
|
|
9
9
|
schema do |t|
|
10
10
|
t.string :name
|
11
11
|
t.integer :price
|
12
|
+
t.boolean :published
|
12
13
|
t.timestamps
|
13
14
|
end
|
14
15
|
|
@@ -19,11 +20,11 @@ end
|
|
19
20
|
def populate
|
20
21
|
5_000.times do |i|
|
21
22
|
puts "Creating product #{i}" if i % 1000 == 0
|
22
|
-
Product.create!(name: "A product with index #{i}", price: 10000 + i % 10)
|
23
|
+
Product.create!(name: "A product with index #{i}", published: true, price: 10000 + i % 10)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
populate if Product.count == 0
|
27
|
+
populate if Product.count == 0
|
27
28
|
|
28
29
|
# 50_000 products: 50M
|
29
30
|
# 100_000 products: 50M
|
data/example/relations.rb
CHANGED
data/lib/groovy/model.rb
CHANGED
@@ -404,12 +404,11 @@ module Groovy
|
|
404
404
|
private
|
405
405
|
|
406
406
|
def get_record_attribute(key)
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
end
|
407
|
+
val = record[key]
|
408
|
+
if self.class.schema.time_column?(key)
|
409
|
+
fix_time_value(val)
|
410
|
+
else
|
411
|
+
val
|
413
412
|
end
|
414
413
|
end
|
415
414
|
|
data/lib/groovy/query.rb
CHANGED
@@ -85,7 +85,7 @@ module Groovy
|
|
85
85
|
add_param(AND + str)
|
86
86
|
|
87
87
|
else
|
88
|
-
str = val.nil? || val
|
88
|
+
str = val.nil? || val === false || val.to_s.strip == '' ? "\"\"" : escape_val(val)
|
89
89
|
add_param(AND + [key, str].join(':'))
|
90
90
|
end
|
91
91
|
end
|
@@ -119,7 +119,7 @@ module Groovy
|
|
119
119
|
add_param(AND + str)
|
120
120
|
|
121
121
|
else
|
122
|
-
str = val.nil? || val
|
122
|
+
str = val.nil? || val === false || val.to_s.strip == '' ? "\"\"" : escape_val(val)
|
123
123
|
add_param(AND + [key, str].join(':!')) # not
|
124
124
|
end
|
125
125
|
end
|
@@ -232,12 +232,8 @@ module Groovy
|
|
232
232
|
attr_reader :model, :table, :options
|
233
233
|
|
234
234
|
def add_param(param)
|
235
|
-
if parameters.include?(param)
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
# if param matches blank/nil, put at the end of the stack
|
240
|
-
param[/:\!?\\/] ? parameters.push(param) : parameters.unshift(param)
|
235
|
+
raise "Duplicate param: #{param}" if parameters.include?(param)
|
236
|
+
parameters.push(param)
|
241
237
|
end
|
242
238
|
|
243
239
|
def results
|
data/lib/groovy/version.rb
CHANGED
data/spec/query_spec.rb
CHANGED
@@ -40,6 +40,13 @@ describe Groovy::Query do
|
|
40
40
|
res = TestProduct.where(tag_list: nil)
|
41
41
|
expect(res.map(&:id)).to eq([@p3.id, @p5.id])
|
42
42
|
end
|
43
|
+
it 'works with other nil values too' do
|
44
|
+
res = TestProduct.where(visible: nil).where(tag_list: nil)
|
45
|
+
expect(res.map(&:id)).to eq([])
|
46
|
+
|
47
|
+
res = TestProduct.where(tag_list: nil).where(name: nil)
|
48
|
+
expect(res.map(&:id)).to eq([])
|
49
|
+
end
|
43
50
|
it 'works with other args too' do
|
44
51
|
res = TestProduct.where(name: 'Product 5').where(tag_list: nil)
|
45
52
|
expect(res.map(&:id)).to eq([@p5.id])
|
@@ -187,6 +194,13 @@ describe Groovy::Query do
|
|
187
194
|
res = TestProduct.where.not(tag_list: nil)
|
188
195
|
expect(res.map(&:id)).to eq([@p1.id, @p2.id, @p4.id])
|
189
196
|
end
|
197
|
+
it 'works with other nil values too' do
|
198
|
+
res = TestProduct.where.not(visible: nil).where(tag_list: nil)
|
199
|
+
expect(res.map(&:id)).to eq([@p3.id, @p5.id])
|
200
|
+
|
201
|
+
res = TestProduct.where.not(tag_list: nil).where(name: nil)
|
202
|
+
expect(res.map(&:id)).to eq([])
|
203
|
+
end
|
190
204
|
it 'works with other args too' do
|
191
205
|
res = TestProduct.where.not(name: 'Product 2').where.not(tag_list: nil)
|
192
206
|
expect(res.map(&:id)).to eq([@p1.id, @p4.id])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groovy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomás Pollak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rroonga
|