toy-dynamo 0.0.8 → 0.0.9
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/README.md +0 -10
- data/lib/toy/dynamo/adapter.rb +1 -1
- data/lib/toy/dynamo/schema.rb +14 -4
- data/lib/toy/dynamo/table.rb +7 -9
- data/lib/toy/dynamo/tasks.rb +16 -4
- data/lib/toy/dynamo/version.rb +1 -1
- data/todo.otl +9 -0
- data/toy-dynamo.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fee8a5ce5e8c53a63a3e3628865248bcad2cd3f4
|
4
|
+
data.tar.gz: 747adb260fc32634e3822ccc400bdeec62287365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c21d126ba6a2c17c9bd1447a921b348e45edac1cc3f26f31e855c881e33f761e533e1bbd926fb8aeb7438633dff06fc4cf005d3089104bd5c5e40a535d880e
|
7
|
+
data.tar.gz: adcab81f3e2a4a68d8a67d19cdd4f24178d95885730898868640a36d5bf7f5362a13108ad8ce16f4cc52a7fa55cee6a424a423536b9be0a08628bfbcd4dd9909
|
data/README.md
CHANGED
@@ -109,13 +109,3 @@ end
|
|
109
109
|
* Tested with
|
110
110
|
* Rails 4
|
111
111
|
* Ruby 2.0.0p0
|
112
|
-
|
113
|
-
## TODO
|
114
|
-
* raise error if trying to use an attribute that wasn't 'select'ed (defaulting to selecting all attributes which loads everything with an extra read)
|
115
|
-
* string and number sets (mostly for scans)
|
116
|
-
* use MAX_ITEM_SIZE (64kb)
|
117
|
-
* fix binary data storage support
|
118
|
-
* add compression (gzip/lzo) => binary
|
119
|
-
* support some sort of rolling tables (for time series type tables)
|
120
|
-
* cross table range queries
|
121
|
-
|
data/lib/toy/dynamo/adapter.rb
CHANGED
@@ -31,7 +31,7 @@ module Toy
|
|
31
31
|
attrs = (result[:member].empty? ? nil : Response.strip_attr_types(result[:member].first))
|
32
32
|
else
|
33
33
|
result = @options[:model].dynamo_table.get_item(key, options)
|
34
|
-
attrs = (result[:item
|
34
|
+
attrs = (result.try(:[], :item).blank? ? nil : Response.strip_attr_types(result[:item]))
|
35
35
|
end
|
36
36
|
|
37
37
|
attrs
|
data/lib/toy/dynamo/schema.rb
CHANGED
@@ -16,15 +16,23 @@ module Toy
|
|
16
16
|
:include => "INCLUDE"
|
17
17
|
}
|
18
18
|
|
19
|
-
def dynamo_table(&block)
|
19
|
+
def dynamo_table(options={}, &block)
|
20
20
|
if block
|
21
21
|
@dynamo_table_config_block ||= block
|
22
22
|
else
|
23
23
|
@dynamo_table_config_block.call unless @dynamo_table_configged
|
24
24
|
|
25
25
|
unless @dynamo_table && @dynamo_table_configged
|
26
|
-
|
27
|
-
|
26
|
+
begin
|
27
|
+
@dynamo_table = Table.new(table_schema, self.adapter.client, options)
|
28
|
+
rescue Exception => e
|
29
|
+
# Reset table_schema
|
30
|
+
@local_secondary_indexes = []
|
31
|
+
raise e
|
32
|
+
end
|
33
|
+
unless options[:novalidate]
|
34
|
+
validate_key_schema if @dynamo_table.schema_loaded_from_dynamo
|
35
|
+
end
|
28
36
|
@dynamo_table_configged = true
|
29
37
|
end
|
30
38
|
@dynamo_table
|
@@ -41,7 +49,7 @@ module Toy
|
|
41
49
|
:key_schema => key_schema,
|
42
50
|
:attribute_definitions => attribute_definitions
|
43
51
|
}
|
44
|
-
schema
|
52
|
+
schema[:local_secondary_indexes] = local_secondary_indexes unless local_secondary_indexes.blank?
|
45
53
|
schema
|
46
54
|
end
|
47
55
|
|
@@ -135,6 +143,7 @@ module Toy
|
|
135
143
|
hash_key_attribute = self.attributes[hash_key_key.to_s]
|
136
144
|
raise(ArgumentError, "Could not find attribute definition for hash_key #{hash_key_key}") unless hash_key_attribute
|
137
145
|
raise(ArgumentError, "Cannot use virtual attributes for hash_key") if hash_key_attribute.virtual?
|
146
|
+
raise(ArgumentError, "Invalid attribute type for hash_key") unless [String, Integer, Float].include?(hash_key_attribute.type)
|
138
147
|
@dynamo_hash_key = {
|
139
148
|
:attribute_name => hash_key_attribute.name,
|
140
149
|
:key_type => KEY_TYPE[:hash]
|
@@ -149,6 +158,7 @@ module Toy
|
|
149
158
|
range_key_attribute = self.attributes[range_key_key.to_s]
|
150
159
|
raise(ArgumentError, "Could not find attribute definition for range_key #{range_key_key}") unless range_key_attribute
|
151
160
|
raise(ArgumentError, "Cannot use virtual attributes for range_key") if range_key_attribute.virtual?
|
161
|
+
raise(ArgumentError, "Invalid attribute type for range_key") unless [String, Integer, Float].include?(range_key_attribute.type)
|
152
162
|
|
153
163
|
validates_presence_of range_key_attribute.name.to_sym
|
154
164
|
|
data/lib/toy/dynamo/table.rb
CHANGED
@@ -34,16 +34,10 @@ module Toy
|
|
34
34
|
:between => "BETWEEN"
|
35
35
|
}
|
36
36
|
|
37
|
-
def initialize(table_schema, client)
|
37
|
+
def initialize(table_schema, client, options={})
|
38
38
|
@table_schema = table_schema
|
39
39
|
@client = client
|
40
|
-
|
41
|
-
self.load_schema
|
42
|
-
rescue AWS::DynamoDB::Errors::ResourceNotFoundException => e
|
43
|
-
Toy::Dynamo::Config.logger.error "No table found!"
|
44
|
-
#self.create
|
45
|
-
#self.load_schema
|
46
|
-
end
|
40
|
+
self.load_schema unless options[:novalidate]
|
47
41
|
end
|
48
42
|
|
49
43
|
def load_schema
|
@@ -67,9 +61,11 @@ module Toy
|
|
67
61
|
if @schema_loaded_from_dynamo[:table][:local_secondary_indexes]
|
68
62
|
@schema_loaded_from_dynamo[:table][:local_secondary_indexes].each do |key|
|
69
63
|
lsi_range_key = key[:key_schema].find{|h| h[:key_type] == "RANGE" }
|
64
|
+
lsi_range_attribute = @table_schema[:attribute_definitions].find{|h| h[:attribute_name] == lsi_range_key[:attribute_name]}
|
65
|
+
next if lsi_range_attribute.nil?
|
70
66
|
(@range_keys ||= []) << {
|
71
67
|
:attribute_name => lsi_range_key[:attribute_name],
|
72
|
-
:attribute_type =>
|
68
|
+
:attribute_type => lsi_range_attribute[:attribute_type],
|
73
69
|
:index_name => key[:index_name]
|
74
70
|
}
|
75
71
|
end
|
@@ -345,6 +341,8 @@ module Toy
|
|
345
341
|
while (table_metadata = self.describe(options))[:table][:table_status] == "CREATING"
|
346
342
|
sleep 1
|
347
343
|
end
|
344
|
+
|
345
|
+
self.load_schema
|
348
346
|
table_metadata
|
349
347
|
end
|
350
348
|
|
data/lib/toy/dynamo/tasks.rb
CHANGED
@@ -4,9 +4,20 @@ namespace :ddb do
|
|
4
4
|
desc 'Create a DynamoDB table'
|
5
5
|
task :create => :environment do
|
6
6
|
raise "expected usage: rake ddb:create CLASS=User" unless ENV['CLASS']
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if ENV["CLASS"] == "all"
|
8
|
+
Toy::Dynamo::Config.included_models.each do |klass|
|
9
|
+
puts "Creating table for #{klass}..."
|
10
|
+
begin
|
11
|
+
klass.dynamo_table(:novalidate => true).create
|
12
|
+
rescue Exception => e
|
13
|
+
puts "Could not create table! #{e.inspect}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
options = {}
|
18
|
+
options.merge!(:table_name => ENV['TABLE']) if ENV['TABLE']
|
19
|
+
ENV['CLASS'].constantize.dynamo_table(:novalidate => true).create(options)
|
20
|
+
end
|
10
21
|
end
|
11
22
|
|
12
23
|
desc 'Resize a DynamoDB table read/write provision'
|
@@ -19,10 +30,11 @@ namespace :ddb do
|
|
19
30
|
ENV['CLASS'].constantize.dynamo_table.resize(options)
|
20
31
|
end
|
21
32
|
|
33
|
+
desc 'Destroy a DynamoDB table'
|
22
34
|
task :destroy => :environment do
|
23
35
|
raise "expected usage: rake ddb:destroy CLASS=User" unless ENV['CLASS']
|
24
36
|
options = {}
|
25
37
|
options.merge!(:table_name => ENV['TABLE']) if ENV['TABLE']
|
26
|
-
ENV['CLASS'].constantize.dynamo_table.delete(options)
|
38
|
+
ENV['CLASS'].constantize.dynamo_table(:novalidate => true).delete(options)
|
27
39
|
end
|
28
40
|
end
|
data/lib/toy/dynamo/version.rb
CHANGED
data/todo.otl
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[_] Batch delete
|
2
|
+
[_] raise error if trying to use an attribute that wasn't 'select'ed (defaulting to selecting all attributes which loads everything with an extra read)
|
3
|
+
[_] string and number sets (mostly for scans)
|
4
|
+
[_] use MAX_ITEM_SIZE (64kb)
|
5
|
+
[_] fix binary data storage support
|
6
|
+
[_] add compression (gzip/lzo) => binary
|
7
|
+
[_] support some sort of rolling tables (for time series type tables)
|
8
|
+
[_] cross table range queries
|
9
|
+
[_] model.reload for models with hash + range
|
data/toy-dynamo.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toy-dynamo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cary Dunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: orm_adapter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: DynamoDB extension to toystore. Provides an ActiveModel based ORM for
|
70
84
|
AWS DynamoDB.
|
71
85
|
email:
|
@@ -99,6 +113,7 @@ files:
|
|
99
113
|
- lib/toy/dynamo/table.rb
|
100
114
|
- lib/toy/dynamo/tasks.rb
|
101
115
|
- lib/toy/dynamo/version.rb
|
116
|
+
- todo.otl
|
102
117
|
- toy-dynamo.gemspec
|
103
118
|
homepage: https://github.com/cdunn/toy-dynamo
|
104
119
|
licenses:
|