dynamini 2.11.1 → 2.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +7 -7
- data/dynamini.gemspec +1 -1
- data/lib/dynamini/querying.rb +18 -11
- data/spec/dynamini/querying_spec.rb +115 -114
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 295d5d3e9ac24824561c2d3ea60328036a2a1ef08cb442c75dc07f07110f05dc
|
4
|
+
data.tar.gz: dc6a149f087e727efed3d20952468639a3ea0b82f3e3acc9d954d9a0a8307153
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70172147217e1531d2be9a15973babb8cbd77361eff4025e39d816e0591e3c4e25278a6b73431b89a4bd5acdc7415f28ed40a9c423b1f0b36ba980151baca358
|
7
|
+
data.tar.gz: 3e8383facfa971c03a77e22ad8399cf5f5d024a88cc65bd67be213eaf0a967a315f5a4a34908c46afd44e1d4835de5d5a130e8d0950ec12282c6e67da206af8b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamini (2.
|
4
|
+
dynamini (2.12.1)
|
5
5
|
activemodel (>= 3, < 5.0)
|
6
6
|
aws-sdk (~> 2)
|
7
7
|
|
@@ -16,13 +16,13 @@ GEM
|
|
16
16
|
minitest (~> 5.1)
|
17
17
|
thread_safe (~> 0.3, >= 0.3.4)
|
18
18
|
tzinfo (~> 1.1)
|
19
|
-
aws-sdk (2.
|
20
|
-
aws-sdk-resources (= 2.
|
21
|
-
aws-sdk-core (2.
|
19
|
+
aws-sdk (2.11.4)
|
20
|
+
aws-sdk-resources (= 2.11.4)
|
21
|
+
aws-sdk-core (2.11.4)
|
22
22
|
aws-sigv4 (~> 1.0)
|
23
23
|
jmespath (~> 1.0)
|
24
|
-
aws-sdk-resources (2.
|
25
|
-
aws-sdk-core (= 2.
|
24
|
+
aws-sdk-resources (2.11.4)
|
25
|
+
aws-sdk-core (= 2.11.4)
|
26
26
|
aws-sigv4 (1.0.2)
|
27
27
|
builder (3.2.3)
|
28
28
|
coderay (1.1.0)
|
@@ -103,4 +103,4 @@ DEPENDENCIES
|
|
103
103
|
rspec (~> 3)
|
104
104
|
|
105
105
|
BUNDLED WITH
|
106
|
-
1.16.
|
106
|
+
1.16.1
|
data/dynamini.gemspec
CHANGED
data/lib/dynamini/querying.rb
CHANGED
@@ -43,6 +43,10 @@ module Dynamini
|
|
43
43
|
def query(args = {})
|
44
44
|
fail ArgumentError, 'You must provide a :hash_key.' unless args[:hash_key]
|
45
45
|
|
46
|
+
if (args[:start] || args[:end]) && !current_index_range_key(args)
|
47
|
+
fail ArgumentError, 'You cannot query using start/end without using an index with a range key.'
|
48
|
+
end
|
49
|
+
|
46
50
|
response = dynamo_query(args)
|
47
51
|
objects = []
|
48
52
|
response.items.each do |item|
|
@@ -69,20 +73,23 @@ module Dynamini
|
|
69
73
|
end
|
70
74
|
|
71
75
|
def build_expression_attribute_values(args)
|
72
|
-
|
76
|
+
expression_values = {':h' => args[:hash_key]}
|
73
77
|
|
74
|
-
if (
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
if current_index_range_key(args)
|
79
|
+
range_key = current_index_range_key(args)
|
80
|
+
|
81
|
+
if (handle = handles[range_key.to_sym])
|
82
|
+
start_val = args[:start] ? attribute_callback(TypeHandler::SETTER_PROCS, handle, args[:start], false) : nil
|
83
|
+
end_val = args[:end] ? attribute_callback(TypeHandler::SETTER_PROCS, handle, args[:end], false) : nil
|
84
|
+
else
|
85
|
+
start_val = args[:start]
|
86
|
+
end_val = args[:end]
|
87
|
+
end
|
88
|
+
|
89
|
+
expression_values[':s'] = start_val if start_val
|
90
|
+
expression_values[':e'] = end_val if end_val
|
80
91
|
end
|
81
92
|
|
82
|
-
expression_values = {}
|
83
|
-
expression_values[':h'] = args[:hash_key]
|
84
|
-
expression_values[':s'] = start_val if start_val
|
85
|
-
expression_values[':e'] = end_val if end_val
|
86
93
|
expression_values
|
87
94
|
end
|
88
95
|
|
@@ -154,140 +154,141 @@ describe Dynamini::Querying do
|
|
154
154
|
end
|
155
155
|
|
156
156
|
describe '.query' do
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
157
|
+
context 'class with range key' do
|
158
|
+
before do
|
159
|
+
4.times do |i|
|
160
|
+
TestClassWithRange.create(foo: 'foo', bar: i + 1, secondary_hash_key: 'secondary_hash_key', secondary_range_key: 10 - i)
|
161
|
+
end
|
162
|
+
TestClassWithRange.create(foo: 'foo2', bar: 5, secondary_hash_key: 'secondary_hash_key', secondary_range_key: 6)
|
163
|
+
end
|
164
|
+
context 'start value provided' do
|
165
|
+
it 'should return records with a range key greater than or equal to the start value' do
|
166
|
+
records = TestClassWithRange.query(hash_key: 'foo', start: 2)
|
167
|
+
expect(records.length).to eq 3
|
168
|
+
expect(records.first.bar).to eq 2
|
169
|
+
expect(records.last.bar).to eq 4
|
170
|
+
end
|
170
171
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
172
|
+
context 'end value provided' do
|
173
|
+
it 'should return records with a range key less than or equal to the start value' do
|
174
|
+
records = TestClassWithRange.query(hash_key: 'foo', end: 2)
|
175
|
+
expect(records.length).to eq 2
|
176
|
+
expect(records.first.bar).to eq 1
|
177
|
+
expect(records.last.bar).to eq 2
|
178
|
+
end
|
178
179
|
end
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
180
|
+
context 'start and end values provided' do
|
181
|
+
it 'should return records between the two values inclusive' do
|
182
|
+
records = TestClassWithRange.query(hash_key: 'foo', start: 1, end: 3)
|
183
|
+
expect(records.length).to eq 3
|
184
|
+
expect(records.first.bar).to eq 1
|
185
|
+
expect(records.last.bar).to eq 3
|
186
|
+
end
|
186
187
|
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
188
|
+
context 'neither value provided' do
|
189
|
+
it 'should return all records belonging to that hash key' do
|
190
|
+
records = TestClassWithRange.query(hash_key: 'foo')
|
191
|
+
expect(records.length).to eq 4
|
192
|
+
expect(records.first.bar).to eq 1
|
193
|
+
expect(records.last.bar).to eq 4
|
194
|
+
end
|
194
195
|
end
|
195
|
-
end
|
196
196
|
|
197
|
-
|
198
|
-
|
199
|
-
|
197
|
+
context 'hash key does not exist' do
|
198
|
+
it 'should return an empty array' do
|
199
|
+
expect(TestClassWithRange.query(hash_key: 'non-existent-key')).to eq([])
|
200
|
+
end
|
200
201
|
end
|
201
|
-
end
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
203
|
+
context 'when :limit is provided' do
|
204
|
+
it 'should return only the first two records' do
|
205
|
+
records = TestClassWithRange.query(hash_key: 'foo', limit: 2)
|
206
|
+
expect(records.length).to eq 2
|
207
|
+
expect(records.first.bar).to eq 1
|
208
|
+
expect(records.last.bar).to eq 2
|
209
|
+
end
|
209
210
|
end
|
210
|
-
end
|
211
211
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
212
|
+
context 'when :scan_index_forward is provided' do
|
213
|
+
it 'should return records in order when given true' do
|
214
|
+
records = TestClassWithRange.query(hash_key: 'foo', scan_index_forward: true)
|
215
|
+
expect(records.length).to eq 4
|
216
|
+
expect(records.first.bar).to eq 1
|
217
|
+
expect(records.last.bar).to eq 4
|
218
|
+
end
|
219
219
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
220
|
+
it 'should return records in reverse order when given false' do
|
221
|
+
records = TestClassWithRange.query(hash_key: 'foo', scan_index_forward: false)
|
222
|
+
expect(records.length).to eq 4
|
223
|
+
expect(records.first.bar).to eq 4
|
224
|
+
expect(records.last.bar).to eq 1
|
225
|
+
end
|
225
226
|
end
|
226
|
-
end
|
227
227
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
228
|
+
context 'using secondary index' do
|
229
|
+
it 'should be able to query using the secondary index' do
|
230
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index)
|
231
|
+
expect(records.length).to eq(5)
|
232
|
+
expect(records.first.secondary_range_key).to eq(6)
|
233
|
+
expect(records.last.secondary_range_key).to eq(10)
|
234
|
+
end
|
235
235
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
236
|
+
it 'should be able to sort backwards' do
|
237
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index, scan_index_forward: false)
|
238
|
+
expect(records.length).to eq(5)
|
239
|
+
expect(records.first.secondary_range_key).to eq(10)
|
240
|
+
expect(records.last.secondary_range_key).to eq(6)
|
241
|
+
end
|
242
242
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
243
|
+
it 'should be able to limit number of results' do
|
244
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index, limit: 3)
|
245
|
+
expect(records.length).to eq(3)
|
246
|
+
expect(records.first.secondary_range_key).to eq(6)
|
247
|
+
expect(records.last.secondary_range_key).to eq(8)
|
248
|
+
end
|
249
249
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
250
|
+
it 'should be able to give a minimum value for the range key' do
|
251
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index, start: 8)
|
252
|
+
expect(records.length).to eq(3)
|
253
|
+
expect(records.first.secondary_range_key).to eq(8)
|
254
|
+
expect(records.last.secondary_range_key).to eq(10)
|
255
|
+
end
|
256
256
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
257
|
+
it 'should be able to give a maximum for the range key' do
|
258
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index, end: 8)
|
259
|
+
expect(records.length).to eq(3)
|
260
|
+
expect(records.first.secondary_range_key).to eq(6)
|
261
|
+
expect(records.last.secondary_range_key).to eq(8)
|
262
|
+
end
|
263
263
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
264
|
+
it 'should be able to give a maximum for the range key' do
|
265
|
+
records = TestClassWithRange.query(hash_key: 'secondary_hash_key', index_name: :secondary_index, start: 7, end: 9)
|
266
|
+
expect(records.length).to eq(3)
|
267
|
+
expect(records.first.secondary_range_key).to eq(7)
|
268
|
+
expect(records.last.secondary_range_key).to eq(9)
|
269
|
+
end
|
270
270
|
|
271
|
-
|
272
|
-
|
271
|
+
it 'should return no results if none are found with the secondary index' do
|
272
|
+
expect(TestClassWithRange.query(hash_key: 'non-existent-key', index_name: :secondary_index)).to eq([])
|
273
|
+
end
|
273
274
|
end
|
274
|
-
end
|
275
275
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
276
|
+
context 'with a type handled range key' do
|
277
|
+
it 'converts the start and end parameter to the raw type' do
|
278
|
+
start_param = Time.new(2000, 1, 1)
|
279
|
+
end_param = Time.new(2001, 1, 1)
|
280
|
+
|
281
|
+
expect(TestClassWithRange.client).to receive(:query).with(hash_including(
|
282
|
+
expression_attribute_values: {':h' => '12345', ':s' => start_param.to_f, ':e' => end_param.to_f}
|
283
|
+
)).and_return(OpenStruct.new(items: []))
|
284
|
+
|
285
|
+
TestClassWithRange.query(
|
286
|
+
hash_key: '12345',
|
287
|
+
index_name: :tertiary_index,
|
288
|
+
start: start_param,
|
289
|
+
end: end_param
|
290
|
+
)
|
291
|
+
end
|
291
292
|
end
|
292
293
|
end
|
293
294
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2018-02-
|
18
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
requirements: []
|
186
186
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.
|
187
|
+
rubygems_version: 2.7.3
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: DynamoDB interface
|