dynamosaurus 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 070ed235ecd54d002a4af5a36cb42ac7c0052c7a
4
- data.tar.gz: 604cb47dc88d5ea6b28db9f313a43f0b55fee132
3
+ metadata.gz: e81e590f83bc8e851d2f00f30b65929119499ef0
4
+ data.tar.gz: 86d65100146300d2a89334c6715f5f0ffbbba5ec
5
5
  SHA512:
6
- metadata.gz: 60a53aaf8e3651d4e778c2b9c2bcbc1439819dbbba4afb475055fcc046b54c0141c6d33b20a0f8a3978a199d7159dedbe3a48cb614f9d6d448e6329a4a517272
7
- data.tar.gz: 8bca0a468f5261405dc01dfec37c501571994018921a31bc400c0cdff40e93485d916db0b49139565fc86f0579228439cdc74aab2cad5bcb427b2a293bb3bad7
6
+ metadata.gz: b061ce9dd7f87f1dffd49a35dbef571088397ed573e3fde419183fe732f01d8a449e56cbf8aac2989218b5d9174f159174e73475376393fdd5376a36dc21bdcf
7
+ data.tar.gz: c017a40360ae6d47fe64e1e383d4bdc0dada2ad191eb718946df5395512f4e012109f8f7c190fb476bf14692c874cd61319f42712e14b90ac5199470da2db38c
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Dynamosaurus
2
2
 
3
+ Dynamosaurus is Amazon DynamoDB ORMapper.
4
+
3
5
  ## Installation
4
6
 
5
7
  Add this line to your application's Gemfile:
@@ -15,7 +15,7 @@ module Dynamosaurus
15
15
  Dynamosaurus::DynamoBase.all_models.each do |model_class|
16
16
  if tables.index(model_class.table_name).nil?
17
17
  table = dynamo_db.create_table(
18
- model_class.get_table_schema
18
+ model_class.schema
19
19
  )
20
20
  end
21
21
  end
@@ -52,12 +52,86 @@ module Dynamosaurus
52
52
  @key
53
53
  end
54
54
 
55
- def table_schema schema = {}
56
- @schema = schema
57
- end
58
-
59
- def get_table_schema
55
+ def schema
56
+ @schema = {}
60
57
  @schema[:table_name] = table_name
58
+ @schema[:key_schema] = []
59
+ @schema[:attribute_definitions] = []
60
+
61
+ @schema[:provisioned_throughput] = {
62
+ :read_capacity_units => 10,
63
+ :write_capacity_units => 10
64
+ }
65
+
66
+ @schema[:key_schema] << {
67
+ :key_type => "HASH",
68
+ :attribute_name => get_key[0].to_s
69
+ }
70
+ @schema[:attribute_definitions] << {:attribute_name => get_key[0].to_s, :attribute_type => get_key[1].to_s.upcase}
71
+
72
+ if get_key.size == 4
73
+ @schema[:key_schema] << {
74
+ :key_type => "RANGE",
75
+ :attribute_name => get_key[2].to_s
76
+ }
77
+ @schema[:attribute_definitions] << {:attribute_name => get_key[2].to_s, :attribute_type => get_key[3].to_s.upcase}
78
+ end
79
+
80
+ unless get_global_indexes.empty?
81
+ @schema[:global_secondary_indexes] = []
82
+ get_global_indexes.each do |g_index|
83
+ index_schema = {
84
+ :index_name => g_index[0],
85
+ :key_schema => [],
86
+ :projection => {
87
+ :projection_type => "KEYS_ONLY",
88
+ },
89
+ :provisioned_throughput => {
90
+ :read_capacity_units => 10,
91
+ :write_capacity_units => 10
92
+ },
93
+ }
94
+ index_schema[:key_schema] << {
95
+ :key_type => "HASH",
96
+ :attribute_name => g_index[1][0]
97
+ }
98
+ @schema[:attribute_definitions] << {:attribute_name => g_index[1][0].to_s, :attribute_type => g_index[1][1].to_s.upcase}
99
+ if g_index[1].size == 4
100
+ index_schema[:key_schema] << {
101
+ :key_type => "RANGE",
102
+ :attribute_name => g_index[1][2]
103
+ }
104
+ @schema[:attribute_definitions] << {:attribute_name => g_index[1][2].to_s, :attribute_type => g_index[1][3].to_s.upcase}
105
+ end
106
+
107
+ @schema[:global_secondary_indexes] << index_schema
108
+ end
109
+ end
110
+ unless get_secondary_indexes.empty?
111
+ @schema[:local_secondary_indexes] = []
112
+ get_secondary_indexes.each do |s_index_key, s_index_value|
113
+ index_schema = {
114
+ :index_name => s_index_key,
115
+ :key_schema => [],
116
+ :projection => {
117
+ :projection_type => "KEYS_ONLY",
118
+ },
119
+ }
120
+ index_schema[:key_schema] =[
121
+ {
122
+ :key_type => "HASH",
123
+ :attribute_name => s_index_value[0]
124
+ },
125
+ {
126
+ :key_type => "RANGE",
127
+ :attribute_name => s_index_value[2]
128
+ }
129
+ ]
130
+ @schema[:attribute_definitions] << {:attribute_name => s_index_value[2].to_s, :attribute_type => s_index_value[3].to_s.upcase}
131
+ @schema[:local_secondary_indexes] << index_schema
132
+ end
133
+ end
134
+
61
135
  @schema
62
136
  end
63
137
 
@@ -87,8 +161,12 @@ module Dynamosaurus
87
161
  @secondary_index[name]
88
162
  end
89
163
 
164
+ def get_indexes
165
+ get_secondary_indexes.merge(get_global_indexes)
166
+ end
167
+
90
168
  def get_index hash
91
- get_secondary_indexes.merge(get_global_indexes).each{|key, value|
169
+ get_indexes.each{|key, value|
92
170
  if hash.size == 1 && hash.keys.first == value.first
93
171
  return {
94
172
  :index_name => key,
@@ -1,3 +1,3 @@
1
1
  module Dynamosaurus
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,102 +2,14 @@
2
2
 
3
3
  class SimpleKVS < Dynamosaurus::DynamoBase
4
4
  key :simple_key, :string
5
-
6
- table_schema :key_schema =>
7
- [
8
- { :key_type => "HASH",
9
- :attribute_name => "simple_key"
10
- }
11
- ],
12
- :provisioned_throughput => {
13
- :read_capacity_units => 100,
14
- :write_capacity_units => 10
15
- },
16
- :attribute_definitions => [
17
- {:attribute_name => "simple_key", :attribute_type => "S"},
18
- ]
19
5
  end
20
6
 
21
7
  class SimpleOrderedKVS < Dynamosaurus::DynamoBase
22
8
  key :simple_key, :string, :simple_id, :string
23
9
  secondary_index :updated_at_index, :updated_at, :number
24
-
25
- table_schema :key_schema =>
26
- [
27
- { :key_type => "HASH",
28
- :attribute_name => "simple_key"
29
- },
30
- { :key_type => "RANGE",
31
- :attribute_name => "simple_id"},
32
- ],
33
- :provisioned_throughput => {
34
- :read_capacity_units => 20,
35
- :write_capacity_units => 10
36
- },
37
- :attribute_definitions => [
38
- {:attribute_name => "simple_key", :attribute_type => "S"},
39
- {:attribute_name => "simple_id", :attribute_type => "S"},
40
- {:attribute_name => "updated_at", :attribute_type => "N"},
41
- ],
42
- :local_secondary_indexes => [
43
- {
44
- :index_name => "updated_at_index",
45
- :key_schema => [
46
- { :key_type => "HASH",
47
- :attribute_name => "simple_key"},
48
-
49
- {
50
- :key_type => "RANGE",
51
- :attribute_name => "updated_at"
52
- }
53
- ],
54
- :projection => {
55
- :projection_type => "ALL"
56
- },
57
- },
58
- ]
59
10
  end
60
11
 
61
12
  class Comment < Dynamosaurus::DynamoBase
62
13
  key :content_id, :string, :message_id, :string
63
14
  global_index :user_index, :user_id, :string
64
-
65
- table_schema :key_schema =>
66
- [
67
- {
68
- :key_type => "HASH",
69
- :attribute_name => "content_id"
70
- },
71
- {
72
- :key_type => "RANGE",
73
- :attribute_name => "message_id"
74
- }
75
- ],
76
- :provisioned_throughput => {
77
- :read_capacity_units => 100,
78
- :write_capacity_units => 10
79
- },
80
- :attribute_definitions => [
81
- {:attribute_name => "content_id", :attribute_type => "S"},
82
- {:attribute_name => "message_id", :attribute_type => "S"},
83
- {:attribute_name => "user_id", :attribute_type => "S"},
84
- ],
85
- :global_secondary_indexes => [
86
- {
87
- :index_name => "user_index",
88
- :key_schema => [
89
- {
90
- :key_type => "HASH",
91
- :attribute_name => "user_id"
92
- },
93
- ],
94
- :projection => {
95
- :projection_type => "KEYS_ONLY",
96
- },
97
- :provisioned_throughput => {
98
- :read_capacity_units => 50,
99
- :write_capacity_units => 10
100
- },
101
- },
102
- ]
103
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamosaurus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Isamu Arimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler