dymos 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dymos.rb +2 -0
- data/lib/dymos/command.rb +4 -4
- data/lib/dymos/model.rb +6 -22
- data/lib/dymos/query/builder.rb +20 -1
- data/lib/dymos/query/describe.rb +11 -0
- data/lib/dymos/query/scan.rb +19 -0
- data/lib/dymos/version.rb +1 -1
- data/spec/lib/dymos/model_spec.rb +1 -1
- data/spec/lib/dymos/query/describe_spec.rb +46 -0
- data/spec/lib/dymos/query/get_item_spec.rb +2 -2
- data/spec/lib/dymos/query/scan_spec.rb +49 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f19efc160366df30ebdf4cf8bddf10b96d7bc52
|
4
|
+
data.tar.gz: fe07218445f99d87f4e43eba77e01fa75d8a18e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 587a325be4f0e04bea0987a232cf3e8a82763db102c02cb3fc54e434284533e45967237af8f18360ac3b2ab21da005df4675190d830f06bec05bdc166a833fa2
|
7
|
+
data.tar.gz: 2435827548726a4c26a45e3743dc214e193f0a61746260ea8ec88284b1abdec30be0573a07188117d3d303b81a6beb9bc576bc93e84e25ab375c008fd7e6d0e9
|
data/lib/dymos.rb
CHANGED
@@ -4,6 +4,8 @@ require "dymos/query/builder"
|
|
4
4
|
require "dymos/query/put_item"
|
5
5
|
require "dymos/query/update_item"
|
6
6
|
require "dymos/query/get_item"
|
7
|
+
require "dymos/query/describe"
|
8
|
+
require "dymos/query/scan"
|
7
9
|
require "dymos/query/query"
|
8
10
|
require "dymos/attribute"
|
9
11
|
require "dymos/command"
|
data/lib/dymos/command.rb
CHANGED
@@ -21,12 +21,12 @@ module Dymos
|
|
21
21
|
Dymos::Query::Query.new(:query, table_name, class_name)
|
22
22
|
end
|
23
23
|
|
24
|
-
def scan
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
24
|
def describe
|
25
|
+
Dymos::Query::Describe.new(:describe_table, table_name, class_name)
|
26
|
+
end
|
29
27
|
|
28
|
+
def scan
|
29
|
+
Dymos::Query::Scan.new(:scan, table_name, class_name)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/dymos/model.rb
CHANGED
@@ -40,31 +40,15 @@ module Dymos
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.all
|
43
|
-
|
44
|
-
result = klass.dynamo.scan({table_name: klass.table_name})
|
45
|
-
result.data[:items].map! { |data|
|
46
|
-
model = Object.const_get(klass.class_name).new
|
47
|
-
model.attributes=data
|
48
|
-
model
|
49
|
-
}
|
43
|
+
self.scan.execute
|
50
44
|
end
|
51
45
|
|
52
|
-
def self.find(key1, key2=nil
|
53
|
-
|
54
|
-
indexes = klass.global_indexes
|
46
|
+
def self.find(key1, key2=nil)
|
47
|
+
indexes = new.global_indexes
|
55
48
|
keys={}
|
56
|
-
keys[indexes.first[:attribute_name]] = key1
|
57
|
-
keys[indexes.last[:attribute_name]] = key2 if indexes.size > 1
|
58
|
-
|
59
|
-
res = klass.dynamo.get_item(
|
60
|
-
table_name: klass.table_name,
|
61
|
-
key: keys,
|
62
|
-
# attributes_to_get: klass.attributes.keys,
|
63
|
-
consistent_read: consistent_read,
|
64
|
-
return_consumed_capacity: 'TOTAL'
|
65
|
-
)
|
66
|
-
klass.attributes = res.data.item
|
67
|
-
klass
|
49
|
+
keys[indexes.first[:attribute_name].to_sym] = key1
|
50
|
+
keys[indexes.last[:attribute_name].to_sym] = key2 if indexes.size > 1
|
51
|
+
self.get.key(keys).execute
|
68
52
|
end
|
69
53
|
|
70
54
|
def save
|
data/lib/dymos/query/builder.rb
CHANGED
@@ -14,9 +14,20 @@ module Dymos
|
|
14
14
|
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def before_send_query(command, query)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def after_send_query(command, query)
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute(client = nil)
|
26
|
+
client ||= Aws::DynamoDB::Client.new
|
18
27
|
begin
|
28
|
+
before_send_query command, query
|
19
29
|
res = client.send command, query
|
30
|
+
after_send_query command, query
|
20
31
|
rescue Aws::DynamoDB::Errors::ConditionalCheckFailedException
|
21
32
|
return false
|
22
33
|
end
|
@@ -32,6 +43,14 @@ module Dymos
|
|
32
43
|
obj = Object.const_get(@class_name).new
|
33
44
|
obj.attributes = res.attributes
|
34
45
|
obj
|
46
|
+
elsif res.respond_to? :data
|
47
|
+
if res.data.respond_to? :item
|
48
|
+
obj = Object.const_get(@class_name).new
|
49
|
+
obj.attributes = res.data.item
|
50
|
+
obj
|
51
|
+
else
|
52
|
+
res.data.to_hash
|
53
|
+
end
|
35
54
|
end
|
36
55
|
else
|
37
56
|
res.data
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Dymos
|
2
|
+
module Query
|
3
|
+
class Scan < ::Dymos::Query::Builder
|
4
|
+
|
5
|
+
def limit(params)
|
6
|
+
@limit = params
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def query
|
11
|
+
data = {
|
12
|
+
table_name: @table_name.to_s,
|
13
|
+
}
|
14
|
+
data[:limit] = @limit if @limit.present?
|
15
|
+
data
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/dymos/version.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
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
|
+
|
8
|
+
client = Aws::DynamoDB::Client.new
|
9
|
+
client.delete_table(table_name: 'test_get_item') if client.list_tables[:table_names].include?('test_get_item')
|
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})
|
26
|
+
|
27
|
+
class TestItem < Dymos::Model
|
28
|
+
table :test_get_item
|
29
|
+
field :id, :string
|
30
|
+
end
|
31
|
+
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
|
+
expect(TestItem.describe.execute[:table][:attribute_definitions]).to eq([{:attribute_name => "id", :attribute_type => "S"}, {:attribute_name => "category_id", :attribute_type => "N"}])
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
describe Dymos::Query::Scan 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
|
+
|
8
|
+
client = Aws::DynamoDB::Client.new
|
9
|
+
client.delete_table(table_name: 'test_get_item') if client.list_tables[:table_names].include?('test_get_item')
|
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})
|
26
|
+
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 2})
|
27
|
+
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 3})
|
28
|
+
client.put_item(table_name: 'test_get_item', item: {id: 'hoge', category_id: 4})
|
29
|
+
|
30
|
+
class TestItem < Dymos::Model
|
31
|
+
table :test_get_item
|
32
|
+
field :id, :string
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:client) { Aws::DynamoDB::Client.new }
|
37
|
+
describe :scan do
|
38
|
+
|
39
|
+
it :query do
|
40
|
+
expect(TestItem.scan.limit(100).query).to eq(table_name: "test_get_item", limit: 100)
|
41
|
+
end
|
42
|
+
|
43
|
+
it :execute do
|
44
|
+
expect(TestItem.scan.execute.size).to eq(5)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
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.4
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,19 +129,23 @@ files:
|
|
129
129
|
- lib/dymos/model.rb
|
130
130
|
- lib/dymos/query/attribute.rb
|
131
131
|
- lib/dymos/query/builder.rb
|
132
|
+
- lib/dymos/query/describe.rb
|
132
133
|
- lib/dymos/query/expect.rb
|
133
134
|
- lib/dymos/query/get_item.rb
|
134
135
|
- lib/dymos/query/put_item.rb
|
135
136
|
- lib/dymos/query/query.rb
|
137
|
+
- lib/dymos/query/scan.rb
|
136
138
|
- lib/dymos/query/update_item.rb
|
137
139
|
- lib/dymos/version.rb
|
138
140
|
- spec/lib/dymos/model_spec.rb
|
139
141
|
- spec/lib/dymos/query/attribute_spec.rb
|
140
142
|
- spec/lib/dymos/query/builder_spec.rb
|
143
|
+
- spec/lib/dymos/query/describe_spec.rb
|
141
144
|
- spec/lib/dymos/query/expect_spec.rb
|
142
145
|
- spec/lib/dymos/query/get_item_spec.rb
|
143
146
|
- spec/lib/dymos/query/put_item_spec.rb
|
144
147
|
- spec/lib/dymos/query/query_spec.rb
|
148
|
+
- spec/lib/dymos/query/scan_spec.rb
|
145
149
|
- spec/lib/dymos/query/update_item_spec.rb
|
146
150
|
- spec/spec_helper.rb
|
147
151
|
homepage: ''
|
@@ -172,9 +176,11 @@ test_files:
|
|
172
176
|
- spec/lib/dymos/model_spec.rb
|
173
177
|
- spec/lib/dymos/query/attribute_spec.rb
|
174
178
|
- spec/lib/dymos/query/builder_spec.rb
|
179
|
+
- spec/lib/dymos/query/describe_spec.rb
|
175
180
|
- spec/lib/dymos/query/expect_spec.rb
|
176
181
|
- spec/lib/dymos/query/get_item_spec.rb
|
177
182
|
- spec/lib/dymos/query/put_item_spec.rb
|
178
183
|
- spec/lib/dymos/query/query_spec.rb
|
184
|
+
- spec/lib/dymos/query/scan_spec.rb
|
179
185
|
- spec/lib/dymos/query/update_item_spec.rb
|
180
186
|
- spec/spec_helper.rb
|