-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_with_hash_key_and_range_key_spec.rb
67 lines (58 loc) · 1.99 KB
/
table_with_hash_key_and_range_key_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require 'aws-sdk-dynamodb'
RSpec.describe 'table with partition (hash) key and sort (range) key' do
it 'saves multiple items by hash and range keys to DynamoDB' do
items = [{k1: 'a1', k2: 'a2'}, {k1: 'a1', k2: 'y'}]
recreate_table('bar', 'k1', 'S', 'k2', 'S')
client = Aws::DynamoDB::Client.new(connection_info)
items.each do |item|
client.put_item({
table_name: 'bar',
item: item
})
end
response = client.query({
table_name: 'bar',
select: 'COUNT',
key_condition_expression: 'k1 = :v_k1',
expression_attribute_values: {
':v_k1': 'a1'
}
})
expect(response.count).to eql(2)
end
it 'supports querying using hash key and comparison on range key using begins_with' do
items = [
{
Id: 206,
Brand: 'Reebok',
Size: 8
},
{
Id: 206,
Brand: 'Nike'
},
{
Id: 206,
Brand: 'Ni Hao'
}
]
recreate_table('shoes', 'Id', 'N', 'Brand', 'S')
client = Aws::DynamoDB::Client.new(connection_info)
items.each do |item|
client.put_item({
table_name: 'shoes',
item: item
})
end
response = client.query({
table_name: 'shoes',
key_condition_expression: 'Id = :v_id AND begins_with(Brand, :v_brand)',
expression_attribute_values: {
':v_id': 206,
':v_brand': 'Ni'
}
})
expect(response.items).not_to be_nil
expect(response.count).to eql(2)
end
end