influxer 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47d8a3e1c19312557c99b513a074c2a1ca38fcb7
4
- data.tar.gz: 9efb4e5a5ee1a3fa9f6aa7fef3d4f594266f67d1
3
+ metadata.gz: b97291ee91b0d574373b50fac3a33d6627b57091
4
+ data.tar.gz: c01bf416f9c8764c509d9e24498b3db71150db2a
5
5
  SHA512:
6
- metadata.gz: 1aca8b3b8005ece22d5b37bd93c4fb4bee7a8ea6ca37609141292fc055c08576c0cb7b405072392fdcbccdd72181093b42dfbe569355c20f566dacd31f47d573
7
- data.tar.gz: 5c4bcb485f464da23f9868c2042856e8f99fb7ea3c0f5d71eff590a2b5604940e8c74f25294ff685aa6748f37cac2040e6bc2cfb2957f01eb5cc4b73f61aff50
6
+ metadata.gz: 2eb6a6dc65620c2dd6ef6d6cff8ad25d524244b6b115e06ed3c689d55726dc10649f15b9054b429d4a96ac4f3a8dfa7cdd394479fd1bf008b1b0f27e19384a34
7
+ data.tar.gz: 6eb53b3436dba96464bb6d8ff06c48f424a38f6576ef596d6ff5a37a6ce1dbedf27b72df3d0d28c8f42cff2a8858335c1516447bed6df93796e997581f512cb2
data/Changelog.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 1.1.1
4
+
5
+ - [Fixes [#31](https://github.com/palkan/influxer/issues/31)] Fix bug with empty arrays in `where` clause
6
+
7
+ - Introduce `Relation#none` method
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Features
@@ -18,7 +24,7 @@ end
18
24
 
19
25
  ### Fixes
20
26
 
21
- - [Fixes #30] Fix writing points with custom retention policy
27
+ - [Fixes [#30](https://github.com/palkan/influxer/issues/30)] Fix writing points with custom retention policy
22
28
 
23
29
  ### Misc
24
30
 
@@ -13,6 +13,25 @@ module Influxer
13
13
  self
14
14
  end
15
15
 
16
+ def none
17
+ where_values << "(#{build_none})"
18
+ self
19
+ end
20
+
21
+ def loaded?
22
+ @null_relation || super
23
+ end
24
+
25
+ def reset
26
+ super
27
+ @null_relation = false
28
+ end
29
+
30
+ def load
31
+ return if @null_relation
32
+ super
33
+ end
34
+
16
35
  protected
17
36
 
18
37
  def build_where(args, hargs, negate)
@@ -40,6 +59,7 @@ module Influxer
40
59
  when Regexp
41
60
  "#{key}#{negate ? ' !~ ' : ' =~ '}#{val.inspect}"
42
61
  when Array
62
+ return build_none if val.empty?
43
63
  build_in(key, val, negate)
44
64
  when Range
45
65
  build_range(key, val, negate)
@@ -65,5 +85,10 @@ module Influxer
65
85
  "#{key} > #{quoted(val.begin)} and #{key} < #{quoted(val.end)}"
66
86
  end
67
87
  end
88
+
89
+ def build_none
90
+ @null_relation = true
91
+ build_eql(1, 0, false)
92
+ end
68
93
  end
69
94
  end
@@ -11,7 +11,7 @@ module Influxer
11
11
  class Relation
12
12
  include Influxer::TimeQuery
13
13
  include Influxer::Calculations
14
- include Influxer::WhereClause
14
+ prepend Influxer::WhereClause
15
15
 
16
16
  attr_reader :values
17
17
 
@@ -256,7 +256,7 @@ module Influxer
256
256
 
257
257
  def reset
258
258
  @values = {}
259
- @records = nil
259
+ @records = []
260
260
  @loaded = false
261
261
  self
262
262
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Influxer # :nodoc:
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.1"
5
5
  end
@@ -88,6 +88,11 @@ describe Influxer::Relation, :query do
88
88
  expect(rel.where(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id = 1 or user_id = 2 or user_id = 3)"
89
89
  end
90
90
 
91
+ it "handle empty arrays", :aggregate_failures do
92
+ expect(rel.where(user_id: []).to_sql).to eq "select * from \"dummy\" where (1 = 0)"
93
+ expect(rel.to_a).to eq []
94
+ end
95
+
91
96
  context "with tags" do
92
97
  it "integer tag values" do
93
98
  expect(rel.where(dummy_id: 10).to_sql).to eq "select * from \"dummy\" where (dummy_id = '10')"
@@ -120,6 +125,11 @@ describe Influxer::Relation, :query do
120
125
  expect(rel.where.not(user_id: [1, 2, 3]).to_sql).to eq "select * from \"dummy\" where (user_id <> 1 and user_id <> 2 and user_id <> 3)"
121
126
  end
122
127
 
128
+ it "handle empty arrays", :aggregate_failures do
129
+ expect(rel.where.not(user_id: []).to_sql).to eq "select * from \"dummy\" where (1 = 0)"
130
+ expect(rel.to_a).to eq []
131
+ end
132
+
123
133
  context "with tags" do
124
134
  it "nil value" do
125
135
  expect(rel.not(dummy_id: nil).to_sql).to eq "select * from \"dummy\" where (dummy_id =~ /.*/)"
@@ -127,6 +137,19 @@ describe Influxer::Relation, :query do
127
137
  end
128
138
  end
129
139
 
140
+ describe "#none" do
141
+ it "returns empty array", :aggregate_failures do
142
+ expect(rel.none.to_sql).to eq "select * from \"dummy\" where (1 = 0)"
143
+ expect(rel.to_a).to eq []
144
+ end
145
+
146
+ it "works with chaining", :aggregate_failures do
147
+ expect(rel.none.where.not(user_id: 1, dummy: :a).to_sql)
148
+ .to eq "select * from \"dummy\" where (1 = 0) and (user_id <> 1) and (dummy <> 'a')"
149
+ expect(rel.to_a).to eq []
150
+ end
151
+ end
152
+
130
153
  describe "#past" do
131
154
  it "work with predefined symbols" do
132
155
  expect(rel.past(:hour).to_sql).to eq "select * from \"dummy\" where (time > now() - 1h)"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Dem
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-29 00:00:00.000000000 Z
11
+ date: 2017-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel