dymos 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -2
- data/lib/dymos/client.rb +16 -0
- data/lib/dymos/config.rb +34 -0
- data/lib/dymos/model.rb +109 -26
- data/lib/dymos/persistence.rb +75 -16
- data/lib/dymos/query/base.rb +23 -0
- data/lib/dymos/query/create_table.rb +72 -0
- data/lib/dymos/query/delete_item.rb +60 -32
- data/lib/dymos/query/describe.rb +3 -5
- data/lib/dymos/query/get_item.rb +30 -9
- data/lib/dymos/query/put_item.rb +67 -41
- data/lib/dymos/query/query.rb +112 -26
- data/lib/dymos/query/scan.rb +85 -12
- data/lib/dymos/query/update_item.rb +97 -50
- data/lib/dymos/version.rb +1 -1
- data/lib/dymos.rb +6 -4
- data/spec/lib/dymos/client_spec.rb +4 -0
- data/spec/lib/dymos/config_spec.rb +11 -0
- data/spec/lib/dymos/data.yml +154 -0
- data/spec/lib/dymos/model_spec.rb +23 -29
- data/spec/lib/dymos/query/create_table_spec.rb +56 -0
- data/spec/lib/dymos/query/delete_item_spec.rb +22 -79
- data/spec/lib/dymos/query/describe_spec.rb +6 -40
- data/spec/lib/dymos/query/get_item_spec.rb +8 -47
- data/spec/lib/dymos/query/put_item_spec.rb +45 -301
- data/spec/lib/dymos/query/query_spec.rb +45 -95
- data/spec/lib/dymos/query/scan_spec.rb +49 -43
- data/spec/lib/dymos/query/update_item_spec.rb +36 -113
- data/spec/lib/dymos/query_spec.rb +150 -0
- data/spec/spec_helper.rb +33 -0
- metadata +16 -12
- data/lib/dymos/command.rb +0 -36
- data/lib/dymos/query/attribute.rb +0 -14
- data/lib/dymos/query/builder.rb +0 -79
- data/lib/dymos/query/expect.rb +0 -65
- data/spec/lib/dymos/query/attribute_spec.rb +0 -15
- data/spec/lib/dymos/query/builder_spec.rb +0 -23
- data/spec/lib/dymos/query/expect_spec.rb +0 -5
@@ -0,0 +1,154 @@
|
|
1
|
+
ProductCatalog:
|
2
|
+
-
|
3
|
+
Id: 101
|
4
|
+
Title: "Book 101 Title"
|
5
|
+
ISBN: "111-1111111111"
|
6
|
+
Authors: "Author 1"
|
7
|
+
Price: -2
|
8
|
+
Dimensions: "8.5 x 11.0 x 0.5"
|
9
|
+
PageCount: 500
|
10
|
+
InPublication: 1
|
11
|
+
ProductCategory: "Book"
|
12
|
+
-
|
13
|
+
Id: 102
|
14
|
+
Title: "Book 102 Title"
|
15
|
+
ISBN: "222-2222222222"
|
16
|
+
Authors: [ "Author 1", "Author 2" ]
|
17
|
+
Price: 20
|
18
|
+
Dimensions: "8.5 x 11.0 x 0.8"
|
19
|
+
PageCount: 600
|
20
|
+
InPublication: 1
|
21
|
+
ProductCategory: "Book"
|
22
|
+
-
|
23
|
+
Id: 103
|
24
|
+
Title: "Book 103 Title"
|
25
|
+
ISBN: "333-3333333333"
|
26
|
+
Authors: [ "Author 1", "Author2", "Author 3" ]
|
27
|
+
Price: 200
|
28
|
+
Dimensions: "8.5 x 11.0 x 1.5"
|
29
|
+
PageCount: "700 InPublication: 0"
|
30
|
+
ProductCategory: "Book"
|
31
|
+
-
|
32
|
+
Id: 201
|
33
|
+
Title: "18-Bicycle 201"
|
34
|
+
Description: "201 description"
|
35
|
+
BicycleType: "Road"
|
36
|
+
Brand: "Brand-Company A"
|
37
|
+
Price: 100
|
38
|
+
Gender: "M"
|
39
|
+
Color: [ "Red", "Black" ]
|
40
|
+
ProductCategory: "Bike"
|
41
|
+
-
|
42
|
+
Id: 202
|
43
|
+
Title: "21-Bicycle 202"
|
44
|
+
Description: "202 description"
|
45
|
+
BicycleType: "Road"
|
46
|
+
Brand: "Brand-Company A"
|
47
|
+
Price: 200
|
48
|
+
Gender: "M"
|
49
|
+
Color: [ "Green", "Black" ]
|
50
|
+
ProductCategory: "Bike"
|
51
|
+
-
|
52
|
+
Id: 203
|
53
|
+
Title: "19-Bicycle 203"
|
54
|
+
Description: "203 description"
|
55
|
+
BicycleType: "Road"
|
56
|
+
Brand: "Brand-Company B"
|
57
|
+
Price: 300
|
58
|
+
Gender: "W"
|
59
|
+
Color: [ "Red", "Green", "Black" ]
|
60
|
+
ProductCategory: "Bike"
|
61
|
+
-
|
62
|
+
Id: 204
|
63
|
+
Title: "18-Bicycle 204"
|
64
|
+
Description: "204 description"
|
65
|
+
BicycleType: "Mountain"
|
66
|
+
Brand: "Brand-Company B"
|
67
|
+
Price: 400
|
68
|
+
Gender: "W"
|
69
|
+
Color: [ "Red" ]
|
70
|
+
ProductCategory: "Bike"
|
71
|
+
-
|
72
|
+
Id: 205
|
73
|
+
Title: "20-Bicycle 205"
|
74
|
+
Description: "205 description"
|
75
|
+
BicycleType: "Hybrid"
|
76
|
+
Brand: "Brand-Company C"
|
77
|
+
Price: 500
|
78
|
+
Gender: "B"
|
79
|
+
Color: [ "Red", "Black" ]
|
80
|
+
ProductCategory: "Bike"
|
81
|
+
|
82
|
+
Forum:
|
83
|
+
-
|
84
|
+
Name: 'DynamoDB'
|
85
|
+
Category: "Amazon Web Services"
|
86
|
+
Threads: 3
|
87
|
+
Messages: 4
|
88
|
+
Views: 1000
|
89
|
+
LastPostBy: "User A"
|
90
|
+
LastPostDateTime: "2012-01-03T00:40:57.165Z"
|
91
|
+
-
|
92
|
+
Name: 'Amazon S3'
|
93
|
+
Category: "AWS"
|
94
|
+
Threads: 1
|
95
|
+
|
96
|
+
Thread:
|
97
|
+
-
|
98
|
+
ForumName: "DynamoDB"
|
99
|
+
Subject: "DynamoDB Thread 1"
|
100
|
+
Message: "DynamoDB thread 1 message text"
|
101
|
+
LastPostedBy: "User A"
|
102
|
+
Views: 0
|
103
|
+
Replies: 0
|
104
|
+
Answered: 0
|
105
|
+
Tags: [ "index", "primarykey", "table" ]
|
106
|
+
LastPostDateTime: "2012-01-03T00:40:57.165Z"
|
107
|
+
-
|
108
|
+
ForumName: "DynamoDB"
|
109
|
+
Subject: "DynamoDB Thread 2"
|
110
|
+
Message: "DynamoDB thread 2 message text"
|
111
|
+
LastPostedBy: "User A"
|
112
|
+
Views: 0
|
113
|
+
Replies: 0
|
114
|
+
Answered: 0
|
115
|
+
Tags: [ "index", "primarykey", "rangekey" ]
|
116
|
+
LastPostDateTime: "2012-01-03T00:40:57.165Z"
|
117
|
+
-
|
118
|
+
ForumName: "Amazon S3"
|
119
|
+
Subject: "Amazon S3 Thread 1"
|
120
|
+
Message: "Amazon S3 Thread 1 message text"
|
121
|
+
LastPostedBy: "User A"
|
122
|
+
Views: 0
|
123
|
+
Replies: 0
|
124
|
+
Answered: 0
|
125
|
+
Tags: [ "largeobject", "multipart upload" ]
|
126
|
+
LastPostDateTime: "2012-01-03T00:40:57.165Z"
|
127
|
+
|
128
|
+
Reply:
|
129
|
+
-
|
130
|
+
Id: "DynamoDB#DynamoDB Thread 1"
|
131
|
+
ReplyDateTime: "2011-12-11T00:40:57.165Z"
|
132
|
+
Message: "DynamoDB Thread 1 Reply 1 text"
|
133
|
+
PostedBy: "User A"
|
134
|
+
-
|
135
|
+
Id: "DynamoDB#DynamoDB Thread 1"
|
136
|
+
ReplyDateTime: "2011-12-18T00:40:57.165Z"
|
137
|
+
Message: "DynamoDB Thread 1 Reply 1 text"
|
138
|
+
PostedBy: "User A"
|
139
|
+
-
|
140
|
+
Id: "DynamoDB#DynamoDB Thread 1"
|
141
|
+
ReplyDateTime: "2011-12-25T00:40:57.165Z"
|
142
|
+
Message: "DynamoDB Thread 1 Reply 3 text"
|
143
|
+
PostedBy: "User B"
|
144
|
+
-
|
145
|
+
Id: "DynamoDB#DynamoDB Thread 2"
|
146
|
+
ReplyDateTime: "2011-12-25T00:40:57.165Z"
|
147
|
+
Message: "DynamoDB Thread 2 Reply 1 text"
|
148
|
+
PostedBy: "User A"
|
149
|
+
-
|
150
|
+
Id: "DynamoDB#DynamoDB Thread 2"
|
151
|
+
ReplyDateTime: "2012-01-03T00:40:57.165Z"
|
152
|
+
Message: "DynamoDB Thread 2 Reply 2"
|
153
|
+
PostedBy: "User A"
|
154
|
+
|
@@ -41,14 +41,8 @@ describe Dymos::Model do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
before :all do
|
44
|
-
|
45
|
-
|
46
|
-
Aws.config[:access_key_id] = 'XXX'
|
47
|
-
Aws.config[:secret_access_key] = 'XXX'
|
48
|
-
client = Aws::DynamoDB::Client.new
|
49
|
-
|
50
|
-
client.delete_table(table_name: 'dummy') if client.list_tables[:table_names].include?('dummy')
|
51
|
-
client.create_table(
|
44
|
+
@client.delete_table(table_name: 'dummy') if @client.list_tables[:table_names].include?('dummy')
|
45
|
+
@client.create_table(
|
52
46
|
table_name: 'dummy',
|
53
47
|
attribute_definitions: [
|
54
48
|
{attribute_name: 'id', attribute_type: 'S'}
|
@@ -60,15 +54,15 @@ describe Dymos::Model do
|
|
60
54
|
read_capacity_units: 1,
|
61
55
|
write_capacity_units: 1,
|
62
56
|
})
|
63
|
-
client.put_item(table_name: 'dummy', item: {id: 'hoge', name: '太郎', list: Set['a', 'b', 'c']})
|
64
|
-
client.put_item(table_name: 'dummy', item: {id: 'fuga', name: '次郎'})
|
65
|
-
client.put_item(table_name: 'dummy', item: {id: 'piyo', name: '三郎'})
|
66
|
-
client.put_item(table_name: 'dummy', item: {id: 'musashi', name: '巴'}) #削除用
|
67
|
-
client.put_item(table_name: 'dummy', item: {id: 'enable_id', name: 'enable', enable: 1})
|
68
|
-
client.put_item(table_name: 'dummy', item: {id: 'disable_id', name: 'disable', enable: 0})
|
69
|
-
|
70
|
-
client.delete_table(table_name: 'post') if client.list_tables[:table_names].include?('post')
|
71
|
-
client.create_table(
|
57
|
+
@client.put_item(table_name: 'dummy', item: {id: 'hoge', name: '太郎', list: Set['a', 'b', 'c']})
|
58
|
+
@client.put_item(table_name: 'dummy', item: {id: 'fuga', name: '次郎'})
|
59
|
+
@client.put_item(table_name: 'dummy', item: {id: 'piyo', name: '三郎'})
|
60
|
+
@client.put_item(table_name: 'dummy', item: {id: 'musashi', name: '巴'}) #削除用
|
61
|
+
@client.put_item(table_name: 'dummy', item: {id: 'enable_id', name: 'enable', enable: 1})
|
62
|
+
@client.put_item(table_name: 'dummy', item: {id: 'disable_id', name: 'disable', enable: 0})
|
63
|
+
|
64
|
+
@client.delete_table(table_name: 'post') if @client.list_tables[:table_names].include?('post')
|
65
|
+
@client.create_table(
|
72
66
|
table_name: 'post',
|
73
67
|
attribute_definitions: [
|
74
68
|
{attribute_name: 'id', attribute_type: 'S'},
|
@@ -188,10 +182,10 @@ describe Dymos::Model do
|
|
188
182
|
|
189
183
|
describe :describe do
|
190
184
|
it "table情報を得る" do
|
191
|
-
|
192
|
-
expect(
|
193
|
-
expect(
|
194
|
-
expect(
|
185
|
+
describe=DummyUser.describe
|
186
|
+
expect(describe[:table][:table_name]).to eq('dummy')
|
187
|
+
expect(describe[:table][:key_schema].first[:attribute_name]).to eq('id')
|
188
|
+
expect(describe[:table][:key_schema].first[:key_type]).to eq('HASH')
|
195
189
|
end
|
196
190
|
end
|
197
191
|
|
@@ -209,7 +203,7 @@ describe Dymos::Model do
|
|
209
203
|
|
210
204
|
describe :find do
|
211
205
|
it "ユーザを抽出" do
|
212
|
-
user = DummyUser.
|
206
|
+
user = DummyUser.find('hoge')
|
213
207
|
expect(user.id).to eq('hoge')
|
214
208
|
expect(user.name).to eq('太郎')
|
215
209
|
end
|
@@ -241,7 +235,7 @@ describe Dymos::Model do
|
|
241
235
|
user.save!
|
242
236
|
user.email = 'hoge@sample.net'
|
243
237
|
Timecop.freeze(now+1)
|
244
|
-
user.
|
238
|
+
user.update!
|
245
239
|
expect(user.created_at.to_s).to eq(now.to_s)
|
246
240
|
expect(user.updated_at.to_s).not_to eq(now.to_s)
|
247
241
|
end
|
@@ -282,7 +276,7 @@ describe Dymos::Model do
|
|
282
276
|
|
283
277
|
describe "DBから引いたモデル" do
|
284
278
|
it "" do
|
285
|
-
user = DummyUser.
|
279
|
+
user = DummyUser.find('hoge')
|
286
280
|
expect(user.changes).to eq({})
|
287
281
|
expect(user.changed?).to eq(false)
|
288
282
|
user.id = 1
|
@@ -304,19 +298,19 @@ describe Dymos::Model do
|
|
304
298
|
|
305
299
|
describe "DBから引いたモデル" do
|
306
300
|
it do
|
307
|
-
user = DummyUser.
|
301
|
+
user = DummyUser.find('musashi')
|
308
302
|
expect(user.new_record?).to eq(false)
|
309
303
|
expect(user.destroyed?).to eq(false)
|
310
304
|
expect(user.persisted?).to eq(true)
|
311
305
|
user.delete
|
312
306
|
expect(user.destroyed?).to eq(true)
|
313
|
-
expect(DummyUser.
|
307
|
+
expect(DummyUser.find('musashi')).to eq(nil)
|
314
308
|
end
|
315
309
|
it 'enableはBoolとして扱われる' do
|
316
|
-
user = DummyUser.
|
310
|
+
user = DummyUser.find('enable_id')
|
317
311
|
expect(user.enable).to eq(true)
|
318
312
|
expect(user.enable?).to eq(true)
|
319
|
-
user = DummyUser.
|
313
|
+
user = DummyUser.find('disable_id')
|
320
314
|
expect(user.enable).to eq(false)
|
321
315
|
expect(user.enable?).to eq(false)
|
322
316
|
end
|
@@ -355,7 +349,7 @@ describe Dymos::Model do
|
|
355
349
|
expect(result).to eq(false)
|
356
350
|
end
|
357
351
|
it "DummyTableをsave!すると例外を返す" do
|
358
|
-
expect{DummyTable.new.save!}.to raise_error
|
352
|
+
expect { DummyTable.new.save! }.to raise_error
|
359
353
|
end
|
360
354
|
end
|
361
355
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
describe Dymos::Query::CreateTable do
|
2
|
+
|
3
|
+
describe 'build query' do
|
4
|
+
let(:builder) { Dymos::Query::CreateTable.new }
|
5
|
+
|
6
|
+
it 'create文生成(スループットデフォルト値)' do
|
7
|
+
builder.name('test_create_table').attributes(id: 'S').keys(id: 'HASH')
|
8
|
+
expect(builder.build).to eq({:table_name => "test_create_table", :attribute_definitions => [{:attribute_name => "id", :attribute_type => "S"}], :key_schema => [{:attribute_name => "id", :key_type => "HASH"}], :provisioned_throughput => {:read_capacity_units => 10, :write_capacity_units => 5}})
|
9
|
+
@client.delete_table(table_name: 'test_create_table') if @client.list_tables[:table_names].include?('test_create_table')
|
10
|
+
@client.create_table(builder.build)
|
11
|
+
end
|
12
|
+
|
13
|
+
it '複雑なクエリ(インデックスのprojection省略するとALLになる)' do
|
14
|
+
builder.name('test_create_table')
|
15
|
+
.attributes(id1: 'S', id2: 'S', id3: 'N')
|
16
|
+
.keys(id1: 'HASH', id2: 'RANGE')
|
17
|
+
.throughput(read: 20, write: 20)
|
18
|
+
.gsi([{name: 'gsi_1', keys: {id2: 'HASH'}, projection: {type: 'INCLUDE', attributes: ['item1', 'item2']}, throughput: {read: 10, write: 10}}])
|
19
|
+
.lsi([{name: 'lsi_1', keys: {id1: 'HASH', id3: 'RANGE'}, throughput: {read: 40, write: 40}}])
|
20
|
+
query = builder.build(provisioned_throughput: {read_capacity_units: 1, write_capacity_units: 1})
|
21
|
+
|
22
|
+
expect(query).to eq({:table_name => "test_create_table",
|
23
|
+
:attribute_definitions => [{:attribute_name => "id1",
|
24
|
+
:attribute_type => "S"},
|
25
|
+
{:attribute_name => "id2",
|
26
|
+
:attribute_type => "S"},
|
27
|
+
{:attribute_name => "id3",
|
28
|
+
:attribute_type => "N"}],
|
29
|
+
:key_schema => [{:attribute_name => "id1",
|
30
|
+
:key_type => "HASH"},
|
31
|
+
{:attribute_name => "id2",
|
32
|
+
:key_type => "RANGE"}],
|
33
|
+
:provisioned_throughput => {:read_capacity_units => 1,
|
34
|
+
:write_capacity_units => 1},
|
35
|
+
:global_secondary_indexes => [{:index_name => "gsi_1",
|
36
|
+
:key_schema => [{:attribute_name => "id2",
|
37
|
+
:key_type => "HASH"}],
|
38
|
+
:projection => {:projection_type => "INCLUDE",
|
39
|
+
:non_key_attributes => ["item1",
|
40
|
+
"item2"]},
|
41
|
+
:provisioned_throughput => {:read_capacity_units => 10,
|
42
|
+
:write_capacity_units => 10}}],
|
43
|
+
:local_secondary_indexes => [{:index_name => "lsi_1",
|
44
|
+
:key_schema => [{:attribute_name => "id1",
|
45
|
+
:key_type => "HASH"},
|
46
|
+
{:attribute_name => "id3",
|
47
|
+
:key_type => "RANGE"}],
|
48
|
+
:projection => {:projection_type => "ALL"}}]})
|
49
|
+
|
50
|
+
@client.delete_table(table_name: 'test_create_table') if @client.list_tables[:table_names].include?('test_create_table')
|
51
|
+
@client.create_table(query)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
@@ -1,90 +1,33 @@
|
|
1
1
|
describe Dymos::Query::DeleteItem do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
Aws.config[:access_key_id] = 'XXX'
|
6
|
-
Aws.config[:secret_access_key] = 'XXX'
|
2
|
+
describe 'build query', order: :defined do
|
3
|
+
let(:builder) { Dymos::Query::DeleteItem.new }
|
4
|
+
let(:table) { 'test_delete_item_table' }
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
{attribute_name: 'id', key_type: 'HASH'}
|
17
|
-
],
|
18
|
-
provisioned_throughput: {
|
19
|
-
read_capacity_units: 1,
|
20
|
-
write_capacity_units: 1,
|
21
|
-
})
|
22
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'hoge', name: '太郎'})
|
23
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'fuga', count: 0})
|
24
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'poyo', name: '可奈'})
|
25
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'puyo', name: '志保'})
|
26
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'piyo', name: '杏奈', count: 10})
|
27
|
-
client.put_item(table_name: 'test_delete_item', item: {id: 'puni', name: '美奈子', count: 10, text: "hoge"})
|
6
|
+
it do
|
7
|
+
@client.delete_table(table_name: table) if @client.list_tables[:table_names].include?(table)
|
8
|
+
query=Dymos::Query::CreateTable.new.name(table).attributes(id: 'S').keys(id: 'HASH').build
|
9
|
+
@client.create_table(query)
|
10
|
+
@client.put_item(table_name: table, item: {id: 'hoge', param1: 101, param2: 201, param3: "hoge", param4: [1, 0, 1]})
|
11
|
+
@client.put_item(table_name: table, item: {id: 'fuga', param1: 102, param2: 202, param3: "fuga", param4: [1, 0, 2]})
|
12
|
+
@client.put_item(table_name: table, item: {id: 'piyo', param1: 103, param2: 203, param3: "piyo", param4: [1, 0, 3]})
|
13
|
+
end
|
28
14
|
|
29
|
-
|
30
|
-
table :
|
31
|
-
|
32
|
-
|
33
|
-
field :count, :string
|
15
|
+
it :key do
|
16
|
+
builder.name(table).key(id: 'hoge').return_values(:ALL_OLD)
|
17
|
+
result = @client.delete_item(builder.build)
|
18
|
+
expect(result[:attributes]["id"]).to eq("hoge")
|
34
19
|
end
|
35
|
-
end
|
36
20
|
|
37
|
-
|
38
|
-
describe :put_item do
|
39
|
-
describe "クエリ生成" do
|
40
|
-
let(:query) { TestItem.delete.key(id: "hoge") }
|
41
|
-
it :query do
|
42
|
-
expect(query.query).to eq({
|
43
|
-
table_name: "test_delete_item",
|
44
|
-
key: {id: "hoge"},
|
45
|
-
return_values: "ALL_OLD",
|
46
|
-
})
|
47
|
-
end
|
48
|
-
it "成功すると削除したアイテムを返す" do
|
49
|
-
res = query.execute client
|
50
|
-
expect(res.id).to eq("hoge")
|
51
|
-
end
|
21
|
+
it :expected do
|
52
22
|
|
53
|
-
|
54
|
-
|
55
|
-
it "条件なし" do
|
56
|
-
query = TestItem.delete.key(id: "poyo")
|
57
|
-
res = query.execute client
|
58
|
-
expect(res.id).to eq("poyo")
|
59
|
-
expect(TestItem.get.key(id: "poyo").execute).to eq(nil)
|
60
|
-
end
|
23
|
+
builder.name(table).key(id: 'fuga').return_values(:ALL_OLD).expected(param1: 0)
|
24
|
+
expect { @client.delete_item(builder.build) }.to raise_error(Aws::DynamoDB::Errors::ConditionalCheckFailedException)
|
61
25
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
expect(res.id).to eq("fuga")
|
66
|
-
expect(TestItem.get.key(id: "fuga").execute).to eq(nil)
|
67
|
-
end
|
68
|
-
it "条件付き2" do
|
69
|
-
query = TestItem.delete.key(id: "puyo").expected(count: 'is_null')
|
70
|
-
res = query.execute
|
71
|
-
expect(res.id).to eq("puyo")
|
72
|
-
expect(TestItem.get.key(id: "puyo").execute).to eq(nil)
|
73
|
-
end
|
74
|
-
it "複数条件条件付き" do
|
75
|
-
query = TestItem.delete.key(id: "puni").expected(count: '== 10', text: '== hoge')
|
76
|
-
res = query.execute
|
77
|
-
expect(res.id).to eq("puni")
|
78
|
-
expect(TestItem.get.key(id: "puni").execute).to eq(nil)
|
79
|
-
end
|
80
|
-
it "条件付き失敗" do
|
81
|
-
query = TestItem.delete.key(id: "piyo").expected(count: "== 1")
|
82
|
-
res = query.execute
|
83
|
-
expect(res).to eq(false)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
26
|
+
builder.name(table).key(id: 'fuga').return_values(:ALL_OLD).expected(param1: 102)
|
27
|
+
result = @client.delete_item(builder.build)
|
28
|
+
expect(result[:attributes]["id"]).to eq("fuga")
|
87
29
|
end
|
30
|
+
|
88
31
|
end
|
89
32
|
end
|
90
33
|
|
@@ -1,47 +1,13 @@
|
|
1
1
|
describe Dymos::Query::Describe do
|
2
|
-
before :all do
|
3
|
-
Aws.config[:region] = 'us-west-1'
|
4
|
-
Aws.config[:endpoint] = 'http://localhost:4567'
|
5
|
-
Aws.config[:access_key_id] = 'XXX'
|
6
|
-
Aws.config[:secret_access_key] = 'XXX'
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
client.create_table(
|
11
|
-
table_name: 'test_get_item',
|
12
|
-
attribute_definitions: [
|
13
|
-
{attribute_name: 'id', attribute_type: 'S'},
|
14
|
-
{attribute_name: 'category_id', attribute_type: 'N'},
|
15
|
-
],
|
16
|
-
key_schema: [
|
17
|
-
{attribute_name: 'id', key_type: 'HASH'},
|
18
|
-
{attribute_name: 'category_id', key_type: 'RANGE'}
|
19
|
-
],
|
20
|
-
provisioned_throughput: {
|
21
|
-
read_capacity_units: 1,
|
22
|
-
write_capacity_units: 1,
|
23
|
-
})
|
24
|
-
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 0, name: '太郎'})
|
25
|
-
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 1})
|
3
|
+
describe 'build query', order: :defined do
|
4
|
+
let(:builder) { Dymos::Query::Describe.new }
|
26
5
|
|
27
|
-
|
28
|
-
|
29
|
-
|
6
|
+
it do
|
7
|
+
builder.name('Thread')
|
8
|
+
result = @client.describe_table(builder.build)
|
9
|
+
expect(result.table[:table_name]).to eq('Thread')
|
30
10
|
end
|
31
11
|
end
|
32
|
-
|
33
|
-
let(:client) { Aws::DynamoDB::Client.new }
|
34
|
-
describe :describe do
|
35
|
-
|
36
|
-
it :query do
|
37
|
-
expect(TestItem.describe.query).to eq(table_name: "test_get_item")
|
38
|
-
end
|
39
|
-
|
40
|
-
it :execute do
|
41
|
-
result=TestItem.describe.execute
|
42
|
-
expect(result[:table][:attribute_definitions]).to eq([{:attribute_name => "id", :attribute_type => "S"}, {:attribute_name => "category_id", :attribute_type => "N"}])
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
12
|
end
|
47
13
|
|
@@ -1,56 +1,17 @@
|
|
1
1
|
describe Dymos::Query::GetItem do
|
2
|
-
before :all do
|
3
|
-
Aws.config[:region] = 'us-west-1'
|
4
|
-
Aws.config[:endpoint] = 'http://localhost:4567'
|
5
|
-
Aws.config[:access_key_id] = 'XXX'
|
6
|
-
Aws.config[:secret_access_key] = 'XXX'
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
client.create_table(
|
11
|
-
table_name: 'test_get_item',
|
12
|
-
attribute_definitions: [
|
13
|
-
{attribute_name: 'id', attribute_type: 'S'},
|
14
|
-
{attribute_name: 'category_id', attribute_type: 'N'},
|
15
|
-
],
|
16
|
-
key_schema: [
|
17
|
-
{attribute_name: 'id', key_type: 'HASH'},
|
18
|
-
{attribute_name: 'category_id', key_type: 'RANGE'}
|
19
|
-
],
|
20
|
-
provisioned_throughput: {
|
21
|
-
read_capacity_units: 1,
|
22
|
-
write_capacity_units: 1,
|
23
|
-
})
|
24
|
-
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 0, name: '太郎'})
|
25
|
-
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 1})
|
3
|
+
describe 'build query' do
|
4
|
+
let(:builder) { Dymos::Query::GetItem.new }
|
26
5
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
6
|
+
subject { @client.get_item(builder.build).item }
|
7
|
+
it do
|
8
|
+
builder.name('Reply').key(Id: "DynamoDB#DynamoDB Thread 1", ReplyDateTime: "2011-12-18T00:40:57.165Z").attributes(:ReplyDateTime, "Message")
|
9
|
+
|
10
|
+
is_expected.to eq({"ReplyDateTime" => "2011-12-18T00:40:57.165Z", "Message" => "DynamoDB Thread 1 Reply 1 text"})
|
31
11
|
end
|
32
12
|
end
|
33
13
|
|
34
|
-
let(:client) { Aws::DynamoDB::Client.new }
|
35
|
-
describe :put_item do
|
36
|
-
describe "クエリ生成" do
|
37
|
-
it "追加のみ" do
|
38
|
-
query = TestItem.get.key(id: 'hoge', category_id: 1)
|
39
|
-
expect(query.query).to eq({
|
40
|
-
table_name: "test_get_item",
|
41
|
-
key: {id: "hoge", category_id: 1},
|
42
|
-
consistent_read: true,
|
43
|
-
})
|
44
|
-
# p client.scan(table_name: "test_get_item")
|
45
|
-
res = query.execute client
|
46
|
-
expect(res.id).to eq('hoge')
|
47
|
-
expect(res.metadata).to eq(consumed_capacity: nil)
|
48
|
-
|
49
|
-
# expect(res).to eq({})
|
50
|
-
# p client.scan(table_name:"test_get_item")
|
51
|
-
end
|
52
14
|
|
53
|
-
end
|
54
|
-
end
|
55
15
|
end
|
56
16
|
|
17
|
+
|