influxdb-arel 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -0
- data/README.md +218 -124
- data/lib/influxdb/arel.rb +25 -16
- data/lib/influxdb/arel/builder.rb +209 -0
- data/lib/influxdb/arel/clauses.rb +6 -0
- data/lib/influxdb/arel/clauses/base.rb +34 -0
- data/lib/influxdb/arel/clauses/expressions.rb +75 -0
- data/lib/influxdb/arel/clauses/from_clause.rb +45 -0
- data/lib/influxdb/arel/clauses/group_clause.rb +34 -0
- data/lib/influxdb/arel/clauses/select_clause.rb +37 -0
- data/lib/influxdb/arel/clauses/where_clause.rb +102 -0
- data/lib/influxdb/arel/core_extensions.rb +5 -21
- data/lib/influxdb/arel/delete_manager.rb +50 -0
- data/lib/influxdb/arel/extensions.rb +6 -0
- data/lib/influxdb/arel/extensions/alias_predication.rb +11 -0
- data/lib/influxdb/arel/extensions/boolean_predications.rb +15 -0
- data/lib/influxdb/arel/extensions/expressions.rb +75 -0
- data/lib/influxdb/arel/extensions/joining_merging.rb +21 -0
- data/lib/influxdb/arel/extensions/math.rb +23 -0
- data/lib/influxdb/arel/extensions/predications.rb +144 -0
- data/lib/influxdb/arel/nodes.rb +7 -14
- data/lib/influxdb/arel/nodes/attribute.rb +20 -0
- data/lib/influxdb/arel/nodes/binary.rb +4 -3
- data/lib/influxdb/arel/nodes/delete_statement.rb +37 -0
- data/lib/influxdb/arel/nodes/duration.rb +3 -3
- data/lib/influxdb/arel/nodes/function.rb +2 -2
- data/lib/influxdb/arel/nodes/grouping.rb +3 -3
- data/lib/influxdb/arel/nodes/infix_operation.rb +11 -4
- data/lib/influxdb/arel/nodes/merge.rb +13 -0
- data/lib/influxdb/arel/nodes/node.rb +18 -6
- data/lib/influxdb/arel/nodes/now.rb +1 -1
- data/lib/influxdb/arel/nodes/ordering.rb +15 -0
- data/lib/influxdb/arel/nodes/select_statement.rb +10 -8
- data/lib/influxdb/arel/nodes/sql_literal.rb +5 -8
- data/lib/influxdb/arel/nodes/table.rb +19 -0
- data/lib/influxdb/arel/nodes/table_alias.rb +2 -4
- data/lib/influxdb/arel/nodes/unary.rb +6 -1
- data/lib/influxdb/arel/quoter.rb +85 -0
- data/lib/influxdb/arel/select_manager.rb +111 -64
- data/lib/influxdb/arel/tree_manager.rb +15 -5
- data/lib/influxdb/arel/version.rb +1 -1
- data/lib/influxdb/arel/visitor.rb +96 -126
- data/lib/influxdb/arel/visitor/delete_statement.rb +32 -0
- data/lib/influxdb/arel/visitor/select_statement.rb +59 -0
- data/lib/influxdb/arel/visitor/where_statement.rb +14 -0
- data/spec/lib/influxdb/arel/builder_spec.rb +173 -0
- data/spec/lib/influxdb/arel/core_extensions_spec.rb +0 -21
- data/spec/lib/influxdb/arel/nodes/and_spec.rb +6 -9
- data/spec/lib/influxdb/arel/nodes/attribute_spec.rb +21 -0
- data/spec/lib/influxdb/arel/nodes/binary_spec.rb +0 -4
- data/spec/lib/influxdb/arel/nodes/duration_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/in_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/infix_operation_spec.rb +17 -0
- data/spec/lib/influxdb/arel/nodes/merge_spec.rb +25 -0
- data/spec/lib/influxdb/arel/nodes/now_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/ordering_spec.rb +19 -0
- data/spec/lib/influxdb/arel/nodes/sql_literal_spec.rb +1 -5
- data/spec/lib/influxdb/arel/nodes/table_alias_spec.rb +3 -10
- data/spec/lib/influxdb/arel/nodes/table_spec.rb +8 -0
- data/spec/lib/influxdb/arel/nodes/unary_spec.rb +0 -4
- data/spec/lib/influxdb/arel/quoter/repository_spec.rb +10 -0
- data/spec/lib/influxdb/arel/quoter_spec.rb +33 -0
- data/spec/lib/influxdb/arel/select_manager_spec.rb +356 -156
- data/spec/lib/influxdb/arel_spec.rb +22 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/examples/binary_node.rb +1 -0
- data/spec/support/examples/function_node.rb +1 -0
- data/spec/support/examples/infix_operation_node.rb +15 -0
- data/spec/support/examples/node_boolean_predications.rb +21 -0
- data/spec/support/examples/node_joining_merging.rb +53 -0
- data/spec/support/examples/unary_node.rb +1 -0
- data/spec/support/fabrics.rb +3 -3
- metadata +49 -11
- data/lib/influxdb/arel/alias_predication.rb +0 -9
- data/lib/influxdb/arel/attributes.rb +0 -1
- data/lib/influxdb/arel/attributes/attribute.rb +0 -74
- data/lib/influxdb/arel/expressions.rb +0 -73
- data/lib/influxdb/arel/math.rb +0 -21
- data/lib/influxdb/arel/predications.rb +0 -137
- data/lib/influxdb/arel/table.rb +0 -219
- data/spec/lib/influxdb/arel/table_spec.rb +0 -193
@@ -8,6 +8,7 @@ describe Influxdb::Arel::Nodes::SqlLiteral do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it_should_behave_like :node_as, 'expressions'
|
11
|
+
it_should_behave_like :node_boolean_predications, 'expressions'
|
11
12
|
it_should_behave_like :node_expressions, 'expressions'
|
12
13
|
it_should_behave_like :node_predications, 'expressions'
|
13
14
|
|
@@ -15,13 +16,8 @@ describe Influxdb::Arel::Nodes::SqlLiteral do
|
|
15
16
|
specify{ expect(described_node.name).to eq(described_node) }
|
16
17
|
end
|
17
18
|
|
18
|
-
describe '#unalias' do
|
19
|
-
specify{ expect(described_node.unalias).to eq(described_node) }
|
20
|
-
end
|
21
|
-
|
22
19
|
describe '#eql?' do
|
23
20
|
specify{ expect(described_node.eql?(node(:SqlLiteral, 'expressions'))).to be_truthy }
|
24
|
-
specify{ expect(described_node.eql?(table('expressions'))).to be_truthy }
|
25
21
|
specify{ expect(described_node.eql?(node(:SqlLiteral, 'expressions1'))).to be_falsy }
|
26
22
|
specify{ expect(described_node.eql?(node(:Fill, 'expressions'))).to be_falsy }
|
27
23
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Influxdb::Arel::Nodes::TableAlias do
|
4
|
-
let(:described_node){ node(:TableAlias,
|
4
|
+
let(:described_node){ node(:TableAlias, node(:Table, 'events'), 'alias') }
|
5
5
|
|
6
6
|
subject{ described_node }
|
7
7
|
|
8
8
|
it_should_behave_like :binary_node, :TableAlias, 'left AS right'
|
9
9
|
|
10
10
|
describe '#relation' do
|
11
|
-
specify{ expect(subject.relation).to eq(
|
11
|
+
specify{ expect(subject.relation).to eq(node(:Table, 'events')) }
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#table_alias' do
|
@@ -19,15 +19,8 @@ describe Influxdb::Arel::Nodes::TableAlias do
|
|
19
19
|
specify{ expect(subject.name).to eq('alias') }
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '#[]' do
|
23
|
-
subject{ described_node[:name] }
|
24
|
-
|
25
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::Attribute) }
|
26
|
-
specify{ expect(visitor.accept(subject)).to eq('alias.name') }
|
27
|
-
end
|
28
|
-
|
29
22
|
describe '#unalias' do
|
30
|
-
specify{ expect(subject.unalias).to eq(
|
23
|
+
specify{ expect(subject.unalias).to eq(node(:Table, 'events')) }
|
31
24
|
end
|
32
25
|
|
33
26
|
describe '#table_name' do
|
@@ -16,10 +16,6 @@ describe Influxdb::Arel::Nodes::Fill do
|
|
16
16
|
it_should_behave_like :unary_node, :Fill, 'fill(value)'
|
17
17
|
end
|
18
18
|
|
19
|
-
describe Influxdb::Arel::Nodes::Ordering do
|
20
|
-
it_should_behave_like :unary_node, :Ordering, 'ORDER VALUE'
|
21
|
-
end
|
22
|
-
|
23
19
|
describe Influxdb::Arel::Nodes::Into do
|
24
20
|
it_should_behave_like :unary_node, :Into, 'INTO value'
|
25
21
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Arel::Quoter::Repository do
|
4
|
+
subject{ Influxdb::Arel::Quoter::Repository.new }
|
5
|
+
|
6
|
+
before{ subject.add(String){|value| "quoted #{value}" } }
|
7
|
+
|
8
|
+
specify{ expect(subject.quote('string')).to eq('quoted string') }
|
9
|
+
specify{ expect(subject.quote(/.*/)).to eq('/.*/') }
|
10
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Influxdb::Arel::Quoter do
|
4
|
+
describe '#quote' do
|
5
|
+
context 'with String' do
|
6
|
+
specify{ expect(subject.quote('string')).to eq("'string'") }
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'with Time' do
|
10
|
+
specify{ expect(subject.quote(Time.parse('2014-10-09 10:49:19 +0700'))).to eq("'2014-10-09 03:49:19'") }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with Date' do
|
14
|
+
specify{ expect(subject.quote(Date.parse('2014-10-09'))).to eq("'2014-10-08'") }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with DateTime' do
|
18
|
+
specify{ expect(subject.quote(DateTime.parse('2014-10-09 10:49:19 +0700'))).to eq("'2014-10-09 03:49:19'") }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with BigDecimal' do
|
22
|
+
specify{ expect(subject.quote(BigDecimal.new('1.03'))).to eq('1.03') }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with NilClass' do
|
26
|
+
specify{ expect(subject.quote(nil)).to eq('null') }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with SqlLiteral' do
|
30
|
+
specify{ expect(subject.quote(sql('SOME SQL'))).to eq('SOME SQL') }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,28 +1,70 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Influxdb::Arel::SelectManager do
|
4
|
-
let(:manager){ Influxdb::Arel::SelectManager.new(
|
4
|
+
let(:manager){ Influxdb::Arel::SelectManager.new(:events) }
|
5
5
|
|
6
6
|
describe '#group' do
|
7
|
-
|
7
|
+
context 'without block' do
|
8
|
+
subject{ manager.group('time(1s)', 'name', :type) }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
11
|
+
specify{ expect(subject.group_values).to eq([
|
12
|
+
node(:Attribute, 'time(1s)'), node(:Attribute, 'name'), node(:Attribute, 'type')
|
13
|
+
]) }
|
14
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with block' do
|
18
|
+
subject{ manager.group{ [time('1s'), name, :type] } }
|
19
|
+
|
20
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
21
|
+
specify{ expect(subject.group_values).to eq([
|
22
|
+
node(:Time, '1s'), node(:Attribute, 'name'), node(:Attribute, 'type')
|
23
|
+
]) }
|
24
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
|
25
|
+
end
|
14
26
|
|
15
27
|
context 'chaining' do
|
16
|
-
subject{
|
28
|
+
subject{ manager.group('time(1s)').group('name', :type) }
|
17
29
|
|
18
30
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
19
|
-
specify{ expect(subject.
|
20
|
-
node(:
|
31
|
+
specify{ expect(subject.group_values).to eq([
|
32
|
+
node(:Attribute, 'time(1s)'), node(:Attribute, 'name'), node(:Attribute, 'type')
|
21
33
|
]) }
|
22
34
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
38
|
+
describe '#group!' do
|
39
|
+
context 'without block' do
|
40
|
+
subject{ manager.group!('time(1s)', 'name', :type) }
|
41
|
+
|
42
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
43
|
+
specify{ expect(subject.group_values).to eq([
|
44
|
+
node(:Attribute, 'time(1s)'), node(:Attribute, 'name'), node(:Attribute, 'type')
|
45
|
+
]) }
|
46
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with block' do
|
50
|
+
subject{ manager.group!{ [time('1s'), name, :type] } }
|
51
|
+
|
52
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
53
|
+
specify{ expect(subject.group_values).to eq([
|
54
|
+
node(:Time, '1s'), node(:Attribute, 'name'), node(:Attribute, 'type')
|
55
|
+
]) }
|
56
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'chaining' do
|
60
|
+
subject{ manager.group('time(1s)').group!('name', :type) }
|
61
|
+
|
62
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
63
|
+
specify{ expect(subject.group_values).to eq([node(:Attribute, 'name'), node(:Attribute, 'type')]) }
|
64
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY name, type') }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
26
68
|
describe '#fill' do
|
27
69
|
context 'with empty groups' do
|
28
70
|
subject{ manager.fill(0) }
|
@@ -58,19 +100,11 @@ describe Influxdb::Arel::SelectManager do
|
|
58
100
|
end
|
59
101
|
|
60
102
|
describe '#from' do
|
61
|
-
context 'with table' do
|
62
|
-
subject{ manager.from(table('table')) }
|
63
|
-
|
64
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
65
|
-
specify{ expect(subject.ast.series).to eq([table('table')]) }
|
66
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
|
67
|
-
end
|
68
|
-
|
69
103
|
context 'with symbol' do
|
70
104
|
subject{ manager.from(:table) }
|
71
105
|
|
72
106
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
73
|
-
specify{ expect(subject.ast.
|
107
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table')]) }
|
74
108
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
|
75
109
|
end
|
76
110
|
|
@@ -78,31 +112,33 @@ describe Influxdb::Arel::SelectManager do
|
|
78
112
|
subject{ manager.from('table') }
|
79
113
|
|
80
114
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
81
|
-
specify{ expect(subject.ast.
|
115
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table')]) }
|
82
116
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
|
83
117
|
end
|
84
118
|
|
85
|
-
context 'with
|
86
|
-
subject{ manager.from
|
119
|
+
context 'with block' do
|
120
|
+
subject{ manager.from{ table } }
|
87
121
|
|
88
122
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
89
|
-
specify{ expect(subject.ast.
|
123
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table')]) }
|
90
124
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
|
91
125
|
end
|
92
126
|
|
93
|
-
context 'with
|
94
|
-
subject{ manager.from(
|
127
|
+
context 'with regexp' do
|
128
|
+
subject{ manager.from(/events\..*/) }
|
95
129
|
|
96
130
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
97
|
-
specify{ expect(subject.ast.
|
98
|
-
specify{ expect(subject.
|
131
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'events')]) }
|
132
|
+
specify{ expect(subject.ast.regexp).to eq(node(:Table, /events\..*/)) }
|
133
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM /events\..*/') }
|
99
134
|
end
|
100
135
|
|
101
|
-
context 'with
|
102
|
-
subject{ manager.from(/events\..*/) }
|
136
|
+
context 'with several regexps' do
|
137
|
+
subject{ manager.from(/events\..*/, /logs\..*/) }
|
103
138
|
|
104
139
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
105
|
-
specify{ expect(subject.ast.
|
140
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'events')]) }
|
141
|
+
specify{ expect(subject.ast.regexp).to eq(node(:Table, /events\..*/)) }
|
106
142
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM /events\..*/') }
|
107
143
|
end
|
108
144
|
|
@@ -110,181 +146,316 @@ describe Influxdb::Arel::SelectManager do
|
|
110
146
|
subject{ manager.from(nil) }
|
111
147
|
|
112
148
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
113
|
-
specify{ expect(subject.ast.
|
149
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'events')]) }
|
114
150
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events') }
|
115
151
|
end
|
116
152
|
|
117
153
|
context 'with several tables' do
|
118
|
-
subject{ manager.from(
|
154
|
+
subject{ manager.from(:table1){ [table2, :table3] } }
|
119
155
|
|
120
156
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
121
|
-
specify{ expect(subject.ast.
|
122
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1, table2') }
|
157
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table1'), node(:Table, 'table2'), node(:Table, 'table3')]) }
|
158
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1, table2, table3') }
|
123
159
|
end
|
124
160
|
|
125
161
|
context 'with several non unique tables' do
|
126
|
-
subject{ manager.from(
|
162
|
+
subject{ manager.from(:table1){ [table1, :table1] } }
|
127
163
|
|
128
164
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
129
|
-
specify{ expect(subject.ast.
|
165
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table1')]) }
|
130
166
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1') }
|
131
167
|
end
|
132
168
|
|
133
169
|
context 'chaining' do
|
134
|
-
subject{ manager.from(
|
170
|
+
subject{ manager.from(:table1).from(:table2) }
|
135
171
|
|
136
172
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
137
|
-
specify{ expect(subject.ast.
|
173
|
+
specify{ expect(subject.ast.tables).to eq([node(:Table, 'table2')]) }
|
138
174
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM table2') }
|
139
175
|
end
|
140
|
-
end
|
141
176
|
|
142
|
-
|
143
|
-
|
144
|
-
|
177
|
+
context 'joining' do
|
178
|
+
let(:alias1){ node(:Table, 'table1').as(:alias1) }
|
179
|
+
let(:alias2){ node(:Table, 'table2').as(:alias2) }
|
145
180
|
|
146
|
-
|
181
|
+
context do
|
182
|
+
subject{ manager.from{ join(:table1, :table2) } }
|
147
183
|
|
148
|
-
|
149
|
-
|
150
|
-
|
184
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
185
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
186
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2') }
|
187
|
+
end
|
151
188
|
|
152
|
-
|
153
|
-
|
189
|
+
context do
|
190
|
+
subject{ manager.from{ join(table1, table2) } }
|
154
191
|
|
155
|
-
|
156
|
-
|
157
|
-
|
192
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
193
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
194
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2') }
|
195
|
+
end
|
196
|
+
|
197
|
+
context do
|
198
|
+
subject{ manager.from{ join(table1.as(:alias1), table2.as(:alias2)) } }
|
199
|
+
|
200
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
201
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, alias1, alias2)) }
|
202
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 AS alias1 INNER JOIN table2 AS alias2') }
|
203
|
+
end
|
204
|
+
|
205
|
+
context do
|
206
|
+
subject{ manager.from(:table1){ join(:table2) } }
|
207
|
+
|
208
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
209
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
210
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2') }
|
211
|
+
end
|
212
|
+
|
213
|
+
context do
|
214
|
+
subject{ manager.from(:table1){ join(table2) } }
|
215
|
+
|
216
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
217
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
218
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2') }
|
219
|
+
end
|
220
|
+
|
221
|
+
context do
|
222
|
+
subject{ manager.from(:table1){ join(table2.as(:alias2)) } }
|
223
|
+
|
224
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
225
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), alias2)) }
|
226
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2 AS alias2') }
|
227
|
+
end
|
228
|
+
|
229
|
+
context do
|
230
|
+
subject{ manager.from{ table1.join(table2.as(:alias2)) } }
|
231
|
+
|
232
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
233
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'table1'), alias2)) }
|
234
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 INNER JOIN table2 AS alias2') }
|
235
|
+
end
|
236
|
+
|
237
|
+
context do
|
238
|
+
subject{ manager.from{ table1.as(:alias1).join(table2.as(:alias2)) } }
|
239
|
+
|
240
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
241
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, alias1, alias2)) }
|
242
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 AS alias1 INNER JOIN table2 AS alias2') }
|
243
|
+
end
|
158
244
|
end
|
159
245
|
|
160
|
-
context '
|
161
|
-
let(:
|
246
|
+
context 'merging' do
|
247
|
+
let(:alias1){ node(:Table, 'table1').as(:alias1) }
|
248
|
+
let(:alias2){ node(:Table, 'table2').as(:alias2) }
|
162
249
|
|
163
|
-
|
250
|
+
context do
|
251
|
+
subject{ manager.from{ merge(:table1, :table2) } }
|
164
252
|
|
165
|
-
|
166
|
-
|
167
|
-
|
253
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
254
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
255
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
256
|
+
end
|
257
|
+
|
258
|
+
context do
|
259
|
+
subject{ manager.from{ merge(table1, table2) } }
|
260
|
+
|
261
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
262
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
263
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
264
|
+
end
|
265
|
+
|
266
|
+
context do
|
267
|
+
subject{ manager.from{ merge(table1.as(:alias1), table2.as(:alias2)) } }
|
268
|
+
|
269
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
270
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, alias1, alias2)) }
|
271
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
272
|
+
end
|
273
|
+
|
274
|
+
context do
|
275
|
+
subject{ manager.from(:table1){ merge(:table2) } }
|
276
|
+
|
277
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
278
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
279
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
280
|
+
end
|
281
|
+
|
282
|
+
context do
|
283
|
+
subject{ manager.from(:table1){ merge(table2) } }
|
284
|
+
|
285
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
286
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), node(:Table, 'table2'))) }
|
287
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
288
|
+
end
|
289
|
+
|
290
|
+
context do
|
291
|
+
subject{ manager.from(:table1){ merge(table2.as(:alias2)) } }
|
292
|
+
|
293
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
294
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), alias2)) }
|
295
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
296
|
+
end
|
297
|
+
|
298
|
+
context do
|
299
|
+
subject{ manager.from{ table1.merge(table2.as(:alias2)) } }
|
300
|
+
|
301
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
302
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'table1'), alias2)) }
|
303
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
304
|
+
end
|
305
|
+
|
306
|
+
context do
|
307
|
+
subject{ manager.from{ table1.as(:alias1).merge(table2.as(:alias2)) } }
|
308
|
+
|
309
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
310
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, alias1, alias2)) }
|
311
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM table1 MERGE table2') }
|
312
|
+
end
|
168
313
|
end
|
314
|
+
end
|
169
315
|
|
170
|
-
|
171
|
-
|
316
|
+
describe '#join' do
|
317
|
+
context 'with one table' do
|
318
|
+
subject{ manager.join(:errors) }
|
172
319
|
|
173
320
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
174
|
-
specify{ expect(subject.ast.join).to eq(node(:Join,
|
175
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM events
|
321
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'events'), node(:Table, 'errors'))) }
|
322
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
|
323
|
+
end
|
324
|
+
|
325
|
+
context 'with two table' do
|
326
|
+
context do
|
327
|
+
let(:manager){ Influxdb::Arel::SelectManager.new }
|
328
|
+
|
329
|
+
subject{ manager.join(:errors, :logs) }
|
330
|
+
|
331
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
332
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'errors'), node(:Table, 'logs'))) }
|
333
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM errors INNER JOIN logs') }
|
334
|
+
end
|
335
|
+
|
336
|
+
context 'and default table' do
|
337
|
+
subject{ manager.join(:errors, :logs) }
|
338
|
+
|
339
|
+
specify{ expect{ subject }.to raise_error }
|
340
|
+
end
|
176
341
|
end
|
177
342
|
|
178
343
|
context 'without argument' do
|
179
344
|
subject{ manager.join }
|
180
|
-
|
181
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
182
|
-
specify{ expect(subject.ast.join).to be_nil }
|
183
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM events') }
|
345
|
+
specify{ expect{ subject }.to raise_error }
|
184
346
|
end
|
185
347
|
|
186
|
-
context 'without argument with many series' do
|
187
|
-
subject{ manager.from(
|
348
|
+
context 'without argument but with many series' do
|
349
|
+
subject{ manager.from(:user_events, :errors).join }
|
188
350
|
|
189
351
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
190
|
-
specify{ expect(subject.ast.join).to eq(node(:Join,
|
352
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
191
353
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events INNER JOIN errors') }
|
192
354
|
end
|
193
355
|
|
194
|
-
context 'without argument with many aliases' do
|
195
|
-
subject{ manager.from(
|
196
|
-
|
197
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
198
|
-
specify{ expect(subject.ast.join).to eq(node(:Join, table_alias1, table_alias2)) }
|
199
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM events AS events1 INNER JOIN events AS events2') }
|
356
|
+
context 'without argument but with too many aliases' do
|
357
|
+
subject{ manager.from(:table1, :table2, :table3).join }
|
358
|
+
specify{ expect{ subject }.to raise_error }
|
200
359
|
end
|
201
360
|
|
202
361
|
context 'with merging' do
|
203
|
-
subject{ manager.from(
|
362
|
+
subject{ manager.from(:user_events, :errors).merge.join }
|
204
363
|
|
205
364
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
206
|
-
specify{ expect(subject.ast.merge).to eq(node(:Merge,
|
207
|
-
specify{ expect(subject.ast.join).to eq(node(:Join,
|
208
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM
|
365
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
366
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
367
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events INNER JOIN errors') }
|
209
368
|
end
|
210
369
|
end
|
211
370
|
|
212
371
|
describe '#merge' do
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
subject{ manager.merge('errors') }
|
217
|
-
|
218
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
219
|
-
specify{ expect(subject.ast.merge).to eq(node(:Merge, table('events'), sql('errors'))) }
|
220
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
|
221
|
-
|
222
|
-
context 'when table as argument' do
|
223
|
-
subject{ manager.merge(table('errors')) }
|
372
|
+
context 'with one table' do
|
373
|
+
subject{ manager.merge(:errors) }
|
224
374
|
|
225
375
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
226
|
-
specify{ expect(subject.ast.merge).to eq(node(:Merge,
|
376
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'events'), node(:Table, 'errors'))) }
|
227
377
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
|
228
378
|
end
|
229
379
|
|
230
|
-
context '
|
231
|
-
|
380
|
+
context 'with two table' do
|
381
|
+
context do
|
382
|
+
let(:manager){ Influxdb::Arel::SelectManager.new }
|
232
383
|
|
233
|
-
|
384
|
+
subject{ manager.merge(:errors, :logs) }
|
234
385
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
386
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
387
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'errors'), node(:Table, 'logs'))) }
|
388
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM errors MERGE logs') }
|
389
|
+
end
|
239
390
|
|
240
|
-
|
241
|
-
|
391
|
+
context 'and default table' do
|
392
|
+
subject{ manager.merge(:errors, :logs) }
|
242
393
|
|
243
|
-
|
394
|
+
specify{ expect{ subject }.to raise_error }
|
395
|
+
end
|
396
|
+
end
|
244
397
|
|
245
|
-
|
246
|
-
|
247
|
-
specify{ expect
|
398
|
+
context 'without argument' do
|
399
|
+
subject{ manager.merge }
|
400
|
+
specify{ expect{ subject }.to raise_error }
|
248
401
|
end
|
249
402
|
|
250
|
-
context 'with
|
251
|
-
subject{ manager.from(
|
403
|
+
context 'without argument but with many tables' do
|
404
|
+
subject{ manager.from(:user_events, :errors).merge }
|
252
405
|
|
253
406
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
254
|
-
specify{ expect(subject.ast.merge).to eq(node(:Merge,
|
255
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM
|
407
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
408
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events MERGE errors') }
|
256
409
|
end
|
257
410
|
|
258
|
-
context 'without argument' do
|
259
|
-
subject{ manager.merge }
|
411
|
+
context 'without argument but with too many tables' do
|
412
|
+
subject{ manager.from(:table1, :table2, :table3).merge }
|
413
|
+
specify{ expect{ subject }.to raise_error }
|
414
|
+
end
|
415
|
+
|
416
|
+
context 'with joining' do
|
417
|
+
subject{ manager.from(:user_events, :errors).join.merge }
|
260
418
|
|
261
419
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
262
|
-
specify{ expect(subject.ast.merge).to
|
263
|
-
specify{ expect(subject.
|
420
|
+
specify{ expect(subject.ast.merge).to eq(node(:Merge, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
421
|
+
specify{ expect(subject.ast.join).to eq(node(:Join, node(:Table, 'user_events'), node(:Table, 'errors'))) }
|
422
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events INNER JOIN errors') }
|
264
423
|
end
|
424
|
+
end
|
425
|
+
|
426
|
+
describe '#select' do
|
427
|
+
let(:nodes){ [node(:Attribute, 'time'), node(:Attribute, 'name'), node(:Attribute, 'age')] }
|
265
428
|
|
266
|
-
|
267
|
-
|
429
|
+
subject{ manager.select(:time){ [name, :age] } }
|
430
|
+
|
431
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
432
|
+
specify{ expect(subject.select_values).to eq(nodes) }
|
433
|
+
specify{ expect(subject.to_sql).to eq('SELECT time, name, age FROM events') }
|
434
|
+
|
435
|
+
context 'chaining' do
|
436
|
+
subject{ manager.select(:time).select{ [name, :age] } }
|
268
437
|
|
269
438
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
270
|
-
specify{ expect(subject.
|
271
|
-
specify{ expect(subject.to_sql).to eq('SELECT
|
439
|
+
specify{ expect(subject.select_values).to eq(nodes) }
|
440
|
+
specify{ expect(subject.to_sql).to eq('SELECT time, name, age FROM events') }
|
272
441
|
end
|
273
442
|
end
|
274
443
|
|
275
|
-
describe '#
|
276
|
-
|
444
|
+
describe '#select!' do
|
445
|
+
let(:nodes){ [node(:Attribute, 'time'), node(:Attribute, 'name'), node(:Attribute, 'age')] }
|
446
|
+
|
447
|
+
subject{ manager.select!(:time){ [name, :age] } }
|
277
448
|
|
278
449
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
279
|
-
specify{ expect(subject.
|
280
|
-
specify{ expect(subject.to_sql).to eq('SELECT time, name,
|
450
|
+
specify{ expect(subject.select_values).to eq(nodes) }
|
451
|
+
specify{ expect(subject.to_sql).to eq('SELECT time, name, age FROM events') }
|
281
452
|
|
282
453
|
context 'chaining' do
|
283
|
-
subject{ manager.
|
454
|
+
subject{ manager.select(:time).select!{ [name, :age] } }
|
284
455
|
|
285
456
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
286
|
-
specify{ expect(subject.
|
287
|
-
specify{ expect(subject.to_sql).to eq('SELECT
|
457
|
+
specify{ expect(subject.select_values).to eq([node(:Attribute, 'name'), node(:Attribute, 'age')]) }
|
458
|
+
specify{ expect(subject.to_sql).to eq('SELECT name, age FROM events') }
|
288
459
|
end
|
289
460
|
end
|
290
461
|
|
@@ -296,7 +467,7 @@ describe Influxdb::Arel::SelectManager do
|
|
296
467
|
subject{ manager.order(:asc) }
|
297
468
|
|
298
469
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
299
|
-
specify{ expect(subject.
|
470
|
+
specify{ expect(subject.order_value).to eq(asc) }
|
300
471
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
301
472
|
end
|
302
473
|
|
@@ -304,7 +475,7 @@ describe Influxdb::Arel::SelectManager do
|
|
304
475
|
subject{ manager.order('asc') }
|
305
476
|
|
306
477
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
307
|
-
specify{ expect(subject.
|
478
|
+
specify{ expect(subject.order_value).to eq(asc) }
|
308
479
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
309
480
|
end
|
310
481
|
|
@@ -312,15 +483,7 @@ describe Influxdb::Arel::SelectManager do
|
|
312
483
|
subject{ manager.order(asc) }
|
313
484
|
|
314
485
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
315
|
-
specify{ expect(subject.
|
316
|
-
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
317
|
-
end
|
318
|
-
|
319
|
-
context 'when sort by ascending order' do
|
320
|
-
subject{ manager.asc }
|
321
|
-
|
322
|
-
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
323
|
-
specify{ expect(subject.ordering).to eq(asc) }
|
486
|
+
specify{ expect(subject.order_value).to eq(asc) }
|
324
487
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
325
488
|
end
|
326
489
|
|
@@ -328,7 +491,7 @@ describe Influxdb::Arel::SelectManager do
|
|
328
491
|
subject{ manager.order(:desc) }
|
329
492
|
|
330
493
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
331
|
-
specify{ expect(subject.
|
494
|
+
specify{ expect(subject.order_value).to eq(desc) }
|
332
495
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
|
333
496
|
end
|
334
497
|
|
@@ -336,7 +499,7 @@ describe Influxdb::Arel::SelectManager do
|
|
336
499
|
subject{ manager.order('desc') }
|
337
500
|
|
338
501
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
339
|
-
specify{ expect(subject.
|
502
|
+
specify{ expect(subject.order_value).to eq(desc) }
|
340
503
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
|
341
504
|
end
|
342
505
|
|
@@ -344,49 +507,86 @@ describe Influxdb::Arel::SelectManager do
|
|
344
507
|
subject{ manager.order(desc) }
|
345
508
|
|
346
509
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
347
|
-
specify{ expect(subject.
|
510
|
+
specify{ expect(subject.order_value).to eq(desc) }
|
348
511
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
|
349
512
|
end
|
350
513
|
|
351
|
-
|
352
|
-
subject{ manager.desc }
|
514
|
+
describe 'chaining' do
|
515
|
+
subject{ manager.order(desc).order(asc) }
|
516
|
+
|
517
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
518
|
+
specify{ expect(subject.order_value).to eq(asc) }
|
519
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
describe '#asc' do
|
524
|
+
subject{ manager.asc }
|
525
|
+
|
526
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
527
|
+
specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
|
528
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
529
|
+
end
|
530
|
+
|
531
|
+
describe '#desc' do
|
532
|
+
subject{ manager.desc }
|
533
|
+
|
534
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
535
|
+
specify{ expect(subject.order_value).to eq(node(:Ordering, 'desc')) }
|
536
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
|
537
|
+
end
|
538
|
+
|
539
|
+
describe '#invert_order' do
|
540
|
+
context 'from native order' do
|
541
|
+
subject{ manager.invert_order }
|
353
542
|
|
354
543
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
355
|
-
specify{ expect(subject.
|
544
|
+
specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
|
545
|
+
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
546
|
+
end
|
547
|
+
|
548
|
+
context 'from asc to desc' do
|
549
|
+
subject{ manager.asc.invert_order }
|
550
|
+
|
551
|
+
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
552
|
+
specify{ expect(subject.order_value).to eq(node(:Ordering, 'desc')) }
|
356
553
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
|
357
554
|
end
|
358
555
|
|
359
|
-
|
360
|
-
subject{ manager.
|
556
|
+
context 'from desc to asc' do
|
557
|
+
subject{ manager.desc.invert_order }
|
361
558
|
|
362
559
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
363
|
-
specify{ expect(subject.
|
560
|
+
specify{ expect(subject.order_value).to eq(node(:Ordering, 'asc')) }
|
364
561
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
|
365
562
|
end
|
366
563
|
end
|
367
564
|
|
368
|
-
describe '#
|
369
|
-
subject{ manager.
|
565
|
+
describe '#limit' do
|
566
|
+
subject{ manager.limit(100) }
|
370
567
|
|
371
568
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
372
|
-
specify{ expect(subject.
|
569
|
+
specify{ expect(subject.limit_value).to eq(node(:Limit, 100)) }
|
373
570
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events LIMIT 100') }
|
374
571
|
|
375
572
|
context 'chaining' do
|
376
|
-
subject{ manager.
|
573
|
+
subject{ manager.limit(100).limit(1) }
|
377
574
|
|
378
575
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
379
|
-
specify{ expect(subject.
|
576
|
+
specify{ expect(subject.limit_value).to eq(node(:Limit, 1)) }
|
380
577
|
specify{ expect(subject.to_sql).to eq('SELECT * FROM events LIMIT 1') }
|
381
578
|
end
|
382
579
|
end
|
383
580
|
|
384
581
|
describe '#where' do
|
582
|
+
let(:equality1){ node(:Equality, node(:Attribute, 'name'), 'Undr') }
|
583
|
+
let(:equality2){ node(:Equality, node(:Attribute, 'age'), 20) }
|
584
|
+
|
385
585
|
context 'with conditions as string' do
|
386
586
|
subject{ manager.where("name = 'Undr'") }
|
387
587
|
|
388
588
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
389
|
-
specify{ expect(subject.
|
589
|
+
specify{ expect(subject.where_values).to eq([sql("name = 'Undr'")]) }
|
390
590
|
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr'") }
|
391
591
|
end
|
392
592
|
|
@@ -394,24 +594,24 @@ describe Influxdb::Arel::SelectManager do
|
|
394
594
|
subject{ manager.where(sql("name = 'Undr'")) }
|
395
595
|
|
396
596
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
397
|
-
specify{ expect(subject.
|
597
|
+
specify{ expect(subject.where_values).to eq([sql("name = 'Undr'")]) }
|
398
598
|
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr'") }
|
399
599
|
end
|
400
600
|
|
401
|
-
context 'with conditions as
|
402
|
-
subject{ manager.where(
|
601
|
+
context 'with conditions as Hash' do
|
602
|
+
subject{ manager.where(name: 'Undr', age: 20) }
|
403
603
|
|
404
604
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
405
|
-
specify{ expect(subject.
|
406
|
-
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr'") }
|
605
|
+
specify{ expect(subject.where_values).to eq([node(:And, [equality1, equality2])]) }
|
606
|
+
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr' AND age = 20") }
|
407
607
|
end
|
408
608
|
|
409
609
|
context 'chaining' do
|
410
|
-
subject{ manager.where(
|
610
|
+
subject{ manager.where(name: 'Undr').where(age: 20) }
|
411
611
|
|
412
612
|
specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
|
413
|
-
specify{ expect(subject.
|
414
|
-
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr' AND
|
613
|
+
specify{ expect(subject.where_values).to eq([equality1, equality2]) }
|
614
|
+
specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr' AND age = 20") }
|
415
615
|
end
|
416
616
|
end
|
417
617
|
|