dymos 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dymos/model.rb +1 -0
- data/lib/dymos/query/builder.rb +24 -6
- data/lib/dymos/version.rb +1 -1
- data/spec/lib/dymos/query/builder_spec.rb +2 -44
- data/spec/lib/dymos/query/describe_spec.rb +2 -1
- data/spec/lib/dymos/query/get_item_spec.rb +1 -1
- data/spec/lib/dymos/query/put_item_spec.rb +8 -6
- data/spec/lib/dymos/query/query_spec.rb +1 -0
- data/spec/lib/dymos/query/scan_spec.rb +3 -1
- data/spec/lib/dymos/query/update_item_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036d8dac33aac8670a6e98ebc1b5edd52acb193f
|
4
|
+
data.tar.gz: bbcc269f35f7a4a717a62937e07281efd24e0f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e60e93b0a7b52e8758d2e62e5c3a3d2c2a810edee67fa0986257651158e2b4e61dffd3617ab65da12709fdc964d534274082cffc9744a8fdfaf7c3affaf57f3
|
7
|
+
data.tar.gz: ac6f103586f8d7d60f28670032e6c4bed0f0fd365dd950f4e739548865fccdaf2c5e7d8b93589283b20a9f45ddaf4e81a4d5d98d7c7399ca790217efe4eb5c6f
|
data/lib/dymos/model.rb
CHANGED
data/lib/dymos/query/builder.rb
CHANGED
@@ -22,7 +22,7 @@ module Dymos
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def raw_execute(client=nil)
|
26
26
|
client ||= Aws::DynamoDB::Client.new
|
27
27
|
begin
|
28
28
|
before_send_query command, query
|
@@ -31,32 +31,50 @@ module Dymos
|
|
31
31
|
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
|
32
32
|
return false
|
33
33
|
end
|
34
|
+
res
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute(client = nil)
|
38
|
+
res = raw_execute client
|
39
|
+
|
40
|
+
return false unless res
|
41
|
+
|
34
42
|
if @class_name.present?
|
35
|
-
if res.data.respond_to? :items
|
43
|
+
if res.data.respond_to? :items # scan, query
|
44
|
+
metadata = extract(res, :items)
|
36
45
|
res.data[:items].map do |datum|
|
37
46
|
obj = Object.const_get(@class_name).new
|
38
47
|
obj.attributes = datum
|
48
|
+
obj.metadata = metadata
|
39
49
|
obj
|
40
50
|
end
|
41
|
-
elsif res.data.respond_to? :attributes
|
51
|
+
elsif res.data.respond_to? :attributes # put_item, update_item
|
42
52
|
return nil if res.attributes.nil?
|
43
53
|
obj = Object.const_get(@class_name).new
|
44
54
|
obj.attributes = res.attributes
|
55
|
+
obj.metadata = extract(res, :attributes)
|
45
56
|
obj
|
46
57
|
elsif res.respond_to? :data
|
47
|
-
if res.data.respond_to? :item
|
58
|
+
if res.data.respond_to? :item # get_item
|
48
59
|
obj = Object.const_get(@class_name).new
|
49
60
|
obj.attributes = res.data.item
|
61
|
+
obj.metadata = extract(res, :item)
|
50
62
|
obj
|
51
63
|
else
|
52
|
-
res.data.to_hash
|
64
|
+
res.data.to_hash # describe
|
53
65
|
end
|
54
66
|
end
|
55
67
|
else
|
56
|
-
res.data
|
68
|
+
res.data.to_hash #list_tables
|
57
69
|
end
|
58
70
|
|
59
71
|
end
|
72
|
+
|
73
|
+
def extract(res, ignoreKey)
|
74
|
+
keys = res.data.members.reject { |a| a == ignoreKey }
|
75
|
+
array=keys.map { |k| [k, res.data[k]] }
|
76
|
+
array.reduce({}) { |hash, value| hash.merge({value[0] => value[1]}) }
|
77
|
+
end
|
60
78
|
end
|
61
79
|
end
|
62
80
|
end
|
data/lib/dymos/version.rb
CHANGED
@@ -14,52 +14,10 @@ describe Dymos::Query::Builder do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "execute" do
|
17
|
-
|
18
|
-
expect(
|
17
|
+
result = query.execute
|
18
|
+
expect(result.include? :table_names).to eq(true)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe :put_item do
|
23
|
-
before :all do
|
24
|
-
client = Aws::DynamoDB::Client.new
|
25
|
-
# client.delete_table(table_name: 'test_put_item') if client.list_tables[:table_names].include?('test_put_item')
|
26
|
-
# client.create_table(
|
27
|
-
# table_name: 'test_put_item',
|
28
|
-
# attribute_definitions: [
|
29
|
-
# {attribute_name: 'id', attribute_type: 'S'}
|
30
|
-
# ],
|
31
|
-
# key_schema: [
|
32
|
-
# {attribute_name: 'id', key_type: 'HASH'}
|
33
|
-
# ],
|
34
|
-
# provisioned_throughput: {
|
35
|
-
# read_capacity_units: 1,
|
36
|
-
# write_capacity_units: 1,
|
37
|
-
# })
|
38
|
-
# client.put_item(table_name: 'test_put_item', item: {id: 'hoge', name: '太郎'})
|
39
|
-
# client.put_item(table_name: 'test_put_item', item: {id: 'fuga', name: '次郎'})
|
40
|
-
# client.put_item(table_name: 'test_put_item', item: {id: 'piyo', name: '三郎'})
|
41
|
-
end
|
42
|
-
let(:client) { Aws::DynamoDB::Client.new }
|
43
|
-
let(:query) { Dymos::Query::Builder.new(:put_item, "test_put_item") }
|
44
|
-
|
45
|
-
it 'put' do
|
46
|
-
# User.put.item(id:"hoge",name:"太郎").expected(id:'hoge')
|
47
|
-
# query.query = {
|
48
|
-
# table_name: query.table_name,
|
49
|
-
# item: {
|
50
|
-
# id: "hoge",
|
51
|
-
# name: "太郎2",
|
52
|
-
# },
|
53
|
-
# expected: {
|
54
|
-
# id: Dymos::Query::Expect.new(:s).condition(:==, 'hoge').data,
|
55
|
-
# name: Dymos::Query::Expect.new(:s).condition(:==, '太郎2').data,
|
56
|
-
# },
|
57
|
-
# return_values: "ALL_OLD",
|
58
|
-
# }
|
59
|
-
# result = query.execute client
|
60
|
-
# expect(result).to eq('hoge')
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
22
|
end
|
65
23
|
|
@@ -38,7 +38,8 @@ describe Dymos::Query::Describe do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it :execute do
|
41
|
-
|
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"}])
|
42
43
|
end
|
43
44
|
|
44
45
|
end
|
@@ -43,7 +43,7 @@ describe Dymos::Query::GetItem do
|
|
43
43
|
# p client.scan(table_name: "test_get_item")
|
44
44
|
res = query.execute client
|
45
45
|
expect(res.id).to eq('hoge')
|
46
|
-
|
46
|
+
expect(res.metadata).to eq(consumed_capacity: nil)
|
47
47
|
|
48
48
|
# expect(res).to eq({})
|
49
49
|
# p client.scan(table_name:"test_get_item")
|
@@ -73,15 +73,16 @@ describe Dymos::Query::PutItem do
|
|
73
73
|
# })
|
74
74
|
# end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
it "条件ありput_item実行 成功すると古いデータを返す" do
|
77
|
+
query = TestItem.put.item(id: "hoge", name: "次郎").expected(name: "== 太郎")
|
78
|
+
result = query.execute client
|
79
|
+
expect(result.attributes).to eq({id: "hoge", name: "太郎"})
|
80
|
+
expect(result.metadata).to eq(consumed_capacity: nil, item_collection_metrics: nil)
|
81
|
+
end
|
81
82
|
|
82
83
|
describe "条件指定" do
|
83
84
|
it "undefined operator" do
|
84
|
-
expect{TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "= 1")}.to raise_error(ArgumentError)
|
85
|
+
expect { TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "= 1") }.to raise_error(ArgumentError)
|
85
86
|
end
|
86
87
|
|
87
88
|
describe :== do
|
@@ -95,6 +96,7 @@ describe Dymos::Query::PutItem do
|
|
95
96
|
it :execute do
|
96
97
|
result = query.execute client
|
97
98
|
expect(result.attributes).to eq({id: "fuga", category_id: 1})
|
99
|
+
expect(result.metadata).to eq(consumed_capacity: nil, item_collection_metrics: nil)
|
98
100
|
end
|
99
101
|
it :error do
|
100
102
|
query = TestItem.put.item(id: "fuga", category_id: 1).expected(category_id: "== 2")
|
@@ -41,7 +41,9 @@ describe Dymos::Query::Scan do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it :execute do
|
44
|
-
|
44
|
+
res=TestItem.scan.execute
|
45
|
+
expect(res.size).to eq(5)
|
46
|
+
expect(res.first.metadata).to eq(count: 5, scanned_count: 5, last_evaluated_key: nil, consumed_capacity: nil)
|
45
47
|
end
|
46
48
|
|
47
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dymos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hoshina85
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|