adept_dynamoid 0.5.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Dynamoid.gemspec +193 -0
  4. data/Gemfile +23 -0
  5. data/Gemfile.lock +86 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.markdown +265 -0
  8. data/Rakefile +62 -0
  9. data/VERSION +1 -0
  10. data/doc/.nojekyll +0 -0
  11. data/doc/Dynamoid.html +312 -0
  12. data/doc/Dynamoid/Adapter.html +1385 -0
  13. data/doc/Dynamoid/Adapter/AwsSdk.html +1585 -0
  14. data/doc/Dynamoid/Adapter/Local.html +1574 -0
  15. data/doc/Dynamoid/Associations.html +131 -0
  16. data/doc/Dynamoid/Associations/Association.html +794 -0
  17. data/doc/Dynamoid/Associations/BelongsTo.html +158 -0
  18. data/doc/Dynamoid/Associations/ClassMethods.html +723 -0
  19. data/doc/Dynamoid/Associations/HasAndBelongsToMany.html +164 -0
  20. data/doc/Dynamoid/Associations/HasMany.html +164 -0
  21. data/doc/Dynamoid/Associations/HasOne.html +158 -0
  22. data/doc/Dynamoid/Associations/ManyAssociation.html +1640 -0
  23. data/doc/Dynamoid/Associations/SingleAssociation.html +598 -0
  24. data/doc/Dynamoid/Components.html +204 -0
  25. data/doc/Dynamoid/Config.html +395 -0
  26. data/doc/Dynamoid/Config/Options.html +609 -0
  27. data/doc/Dynamoid/Criteria.html +131 -0
  28. data/doc/Dynamoid/Criteria/Chain.html +1063 -0
  29. data/doc/Dynamoid/Criteria/ClassMethods.html +98 -0
  30. data/doc/Dynamoid/Document.html +666 -0
  31. data/doc/Dynamoid/Document/ClassMethods.html +937 -0
  32. data/doc/Dynamoid/Errors.html +118 -0
  33. data/doc/Dynamoid/Errors/DocumentNotValid.html +210 -0
  34. data/doc/Dynamoid/Errors/Error.html +130 -0
  35. data/doc/Dynamoid/Errors/InvalidField.html +133 -0
  36. data/doc/Dynamoid/Errors/MissingRangeKey.html +133 -0
  37. data/doc/Dynamoid/Fields.html +669 -0
  38. data/doc/Dynamoid/Fields/ClassMethods.html +309 -0
  39. data/doc/Dynamoid/Finders.html +128 -0
  40. data/doc/Dynamoid/Finders/ClassMethods.html +516 -0
  41. data/doc/Dynamoid/Indexes.html +308 -0
  42. data/doc/Dynamoid/Indexes/ClassMethods.html +353 -0
  43. data/doc/Dynamoid/Indexes/Index.html +1104 -0
  44. data/doc/Dynamoid/Persistence.html +651 -0
  45. data/doc/Dynamoid/Persistence/ClassMethods.html +670 -0
  46. data/doc/Dynamoid/Validations.html +399 -0
  47. data/doc/_index.html +461 -0
  48. data/doc/class_list.html +47 -0
  49. data/doc/css/common.css +1 -0
  50. data/doc/css/full_list.css +55 -0
  51. data/doc/css/style.css +322 -0
  52. data/doc/file.LICENSE.html +66 -0
  53. data/doc/file.README.html +312 -0
  54. data/doc/file_list.html +52 -0
  55. data/doc/frames.html +13 -0
  56. data/doc/index.html +312 -0
  57. data/doc/js/app.js +205 -0
  58. data/doc/js/full_list.js +173 -0
  59. data/doc/js/jquery.js +16 -0
  60. data/doc/method_list.html +1238 -0
  61. data/doc/top-level-namespace.html +105 -0
  62. data/lib/dynamoid.rb +47 -0
  63. data/lib/dynamoid/adapter.rb +177 -0
  64. data/lib/dynamoid/adapter/aws_sdk.rb +223 -0
  65. data/lib/dynamoid/associations.rb +106 -0
  66. data/lib/dynamoid/associations/association.rb +105 -0
  67. data/lib/dynamoid/associations/belongs_to.rb +44 -0
  68. data/lib/dynamoid/associations/has_and_belongs_to_many.rb +40 -0
  69. data/lib/dynamoid/associations/has_many.rb +39 -0
  70. data/lib/dynamoid/associations/has_one.rb +39 -0
  71. data/lib/dynamoid/associations/many_association.rb +191 -0
  72. data/lib/dynamoid/associations/single_association.rb +69 -0
  73. data/lib/dynamoid/components.rb +36 -0
  74. data/lib/dynamoid/config.rb +57 -0
  75. data/lib/dynamoid/config/options.rb +78 -0
  76. data/lib/dynamoid/criteria.rb +29 -0
  77. data/lib/dynamoid/criteria/chain.rb +243 -0
  78. data/lib/dynamoid/dirty.rb +41 -0
  79. data/lib/dynamoid/document.rb +184 -0
  80. data/lib/dynamoid/errors.rb +28 -0
  81. data/lib/dynamoid/fields.rb +130 -0
  82. data/lib/dynamoid/finders.rb +131 -0
  83. data/lib/dynamoid/identity_map.rb +96 -0
  84. data/lib/dynamoid/indexes.rb +69 -0
  85. data/lib/dynamoid/indexes/index.rb +103 -0
  86. data/lib/dynamoid/middleware/identity_map.rb +16 -0
  87. data/lib/dynamoid/persistence.rb +247 -0
  88. data/lib/dynamoid/validations.rb +36 -0
  89. data/spec/app/models/address.rb +10 -0
  90. data/spec/app/models/camel_case.rb +24 -0
  91. data/spec/app/models/magazine.rb +11 -0
  92. data/spec/app/models/message.rb +9 -0
  93. data/spec/app/models/sponsor.rb +8 -0
  94. data/spec/app/models/subscription.rb +12 -0
  95. data/spec/app/models/tweet.rb +12 -0
  96. data/spec/app/models/user.rb +26 -0
  97. data/spec/dynamoid/adapter/aws_sdk_spec.rb +186 -0
  98. data/spec/dynamoid/adapter_spec.rb +117 -0
  99. data/spec/dynamoid/associations/association_spec.rb +194 -0
  100. data/spec/dynamoid/associations/belongs_to_spec.rb +71 -0
  101. data/spec/dynamoid/associations/has_and_belongs_to_many_spec.rb +47 -0
  102. data/spec/dynamoid/associations/has_many_spec.rb +42 -0
  103. data/spec/dynamoid/associations/has_one_spec.rb +45 -0
  104. data/spec/dynamoid/associations_spec.rb +16 -0
  105. data/spec/dynamoid/config_spec.rb +27 -0
  106. data/spec/dynamoid/criteria/chain_spec.rb +140 -0
  107. data/spec/dynamoid/criteria_spec.rb +72 -0
  108. data/spec/dynamoid/dirty_spec.rb +49 -0
  109. data/spec/dynamoid/document_spec.rb +118 -0
  110. data/spec/dynamoid/fields_spec.rb +127 -0
  111. data/spec/dynamoid/finders_spec.rb +135 -0
  112. data/spec/dynamoid/identity_map_spec.rb +45 -0
  113. data/spec/dynamoid/indexes/index_spec.rb +104 -0
  114. data/spec/dynamoid/indexes_spec.rb +25 -0
  115. data/spec/dynamoid/persistence_spec.rb +176 -0
  116. data/spec/dynamoid/validations_spec.rb +36 -0
  117. data/spec/dynamoid_spec.rb +9 -0
  118. data/spec/spec_helper.rb +50 -0
  119. metadata +376 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Dynamoid.gemspec ADDED
@@ -0,0 +1,193 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "adept_dynamoid"
8
+ s.version = "0.5.0.6"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Josh Symonds"]
12
+ s.date = "2012-08-22"
13
+ s.description = "Dynamoid is an ORM for Amazon's DynamoDB that supports offline development, associations, querying, and everything else you'd expect from an ActiveRecord-style replacement."
14
+ s.email = "josh@joshsymonds.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Dynamoid.gemspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "doc/.nojekyll",
30
+ "doc/Dynamoid.html",
31
+ "doc/Dynamoid/Adapter.html",
32
+ "doc/Dynamoid/Adapter/AwsSdk.html",
33
+ "doc/Dynamoid/Adapter/Local.html",
34
+ "doc/Dynamoid/Associations.html",
35
+ "doc/Dynamoid/Associations/Association.html",
36
+ "doc/Dynamoid/Associations/BelongsTo.html",
37
+ "doc/Dynamoid/Associations/ClassMethods.html",
38
+ "doc/Dynamoid/Associations/HasAndBelongsToMany.html",
39
+ "doc/Dynamoid/Associations/HasMany.html",
40
+ "doc/Dynamoid/Associations/HasOne.html",
41
+ "doc/Dynamoid/Associations/ManyAssociation.html",
42
+ "doc/Dynamoid/Associations/SingleAssociation.html",
43
+ "doc/Dynamoid/Components.html",
44
+ "doc/Dynamoid/Config.html",
45
+ "doc/Dynamoid/Config/Options.html",
46
+ "doc/Dynamoid/Criteria.html",
47
+ "doc/Dynamoid/Criteria/Chain.html",
48
+ "doc/Dynamoid/Criteria/ClassMethods.html",
49
+ "doc/Dynamoid/Document.html",
50
+ "doc/Dynamoid/Document/ClassMethods.html",
51
+ "doc/Dynamoid/Errors.html",
52
+ "doc/Dynamoid/Errors/DocumentNotValid.html",
53
+ "doc/Dynamoid/Errors/Error.html",
54
+ "doc/Dynamoid/Errors/InvalidField.html",
55
+ "doc/Dynamoid/Errors/MissingRangeKey.html",
56
+ "doc/Dynamoid/Fields.html",
57
+ "doc/Dynamoid/Fields/ClassMethods.html",
58
+ "doc/Dynamoid/Finders.html",
59
+ "doc/Dynamoid/Finders/ClassMethods.html",
60
+ "doc/Dynamoid/Indexes.html",
61
+ "doc/Dynamoid/Indexes/ClassMethods.html",
62
+ "doc/Dynamoid/Indexes/Index.html",
63
+ "doc/Dynamoid/Persistence.html",
64
+ "doc/Dynamoid/Persistence/ClassMethods.html",
65
+ "doc/Dynamoid/Validations.html",
66
+ "doc/_index.html",
67
+ "doc/class_list.html",
68
+ "doc/css/common.css",
69
+ "doc/css/full_list.css",
70
+ "doc/css/style.css",
71
+ "doc/file.LICENSE.html",
72
+ "doc/file.README.html",
73
+ "doc/file_list.html",
74
+ "doc/frames.html",
75
+ "doc/index.html",
76
+ "doc/js/app.js",
77
+ "doc/js/full_list.js",
78
+ "doc/js/jquery.js",
79
+ "doc/method_list.html",
80
+ "doc/top-level-namespace.html",
81
+ "lib/dynamoid.rb",
82
+ "lib/dynamoid/adapter.rb",
83
+ "lib/dynamoid/adapter/aws_sdk.rb",
84
+ "lib/dynamoid/associations.rb",
85
+ "lib/dynamoid/associations/association.rb",
86
+ "lib/dynamoid/associations/belongs_to.rb",
87
+ "lib/dynamoid/associations/has_and_belongs_to_many.rb",
88
+ "lib/dynamoid/associations/has_many.rb",
89
+ "lib/dynamoid/associations/has_one.rb",
90
+ "lib/dynamoid/associations/many_association.rb",
91
+ "lib/dynamoid/associations/single_association.rb",
92
+ "lib/dynamoid/components.rb",
93
+ "lib/dynamoid/config.rb",
94
+ "lib/dynamoid/config/options.rb",
95
+ "lib/dynamoid/criteria.rb",
96
+ "lib/dynamoid/criteria/chain.rb",
97
+ "lib/dynamoid/dirty.rb",
98
+ "lib/dynamoid/document.rb",
99
+ "lib/dynamoid/errors.rb",
100
+ "lib/dynamoid/fields.rb",
101
+ "lib/dynamoid/finders.rb",
102
+ "lib/dynamoid/identity_map.rb",
103
+ "lib/dynamoid/indexes.rb",
104
+ "lib/dynamoid/indexes/index.rb",
105
+ "lib/dynamoid/middleware/identity_map.rb",
106
+ "lib/dynamoid/persistence.rb",
107
+ "lib/dynamoid/validations.rb",
108
+ "spec/app/models/address.rb",
109
+ "spec/app/models/camel_case.rb",
110
+ "spec/app/models/magazine.rb",
111
+ "spec/app/models/message.rb",
112
+ "spec/app/models/sponsor.rb",
113
+ "spec/app/models/subscription.rb",
114
+ "spec/app/models/tweet.rb",
115
+ "spec/app/models/user.rb",
116
+ "spec/dynamoid/adapter/aws_sdk_spec.rb",
117
+ "spec/dynamoid/adapter_spec.rb",
118
+ "spec/dynamoid/associations/association_spec.rb",
119
+ "spec/dynamoid/associations/belongs_to_spec.rb",
120
+ "spec/dynamoid/associations/has_and_belongs_to_many_spec.rb",
121
+ "spec/dynamoid/associations/has_many_spec.rb",
122
+ "spec/dynamoid/associations/has_one_spec.rb",
123
+ "spec/dynamoid/associations_spec.rb",
124
+ "spec/dynamoid/config_spec.rb",
125
+ "spec/dynamoid/criteria/chain_spec.rb",
126
+ "spec/dynamoid/criteria_spec.rb",
127
+ "spec/dynamoid/dirty_spec.rb",
128
+ "spec/dynamoid/document_spec.rb",
129
+ "spec/dynamoid/fields_spec.rb",
130
+ "spec/dynamoid/finders_spec.rb",
131
+ "spec/dynamoid/identity_map_spec.rb",
132
+ "spec/dynamoid/indexes/index_spec.rb",
133
+ "spec/dynamoid/indexes_spec.rb",
134
+ "spec/dynamoid/persistence_spec.rb",
135
+ "spec/dynamoid/validations_spec.rb",
136
+ "spec/dynamoid_spec.rb",
137
+ "spec/spec_helper.rb"
138
+ ]
139
+ s.homepage = "http://github.com/Veraticus/Dynamoid"
140
+ s.licenses = ["MIT"]
141
+ s.require_paths = ["lib"]
142
+ s.rubygems_version = "1.8.23"
143
+ s.summary = "Dynamoid is an ORM for Amazon's DynamoDB"
144
+
145
+ if s.respond_to? :specification_version then
146
+ s.specification_version = 3
147
+
148
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
149
+ s.add_runtime_dependency(%q<activemodel>, [">= 0"])
150
+ s.add_runtime_dependency(%q<tzinfo>, [">= 0"])
151
+ s.add_runtime_dependency(%q<aws-sdk>, [">= 0"])
152
+ s.add_development_dependency(%q<rake>, [">= 0"])
153
+ s.add_development_dependency(%q<rspec>, [">= 0"])
154
+ s.add_development_dependency(%q<bundler>, [">= 0"])
155
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
156
+ s.add_development_dependency(%q<yard>, [">= 0"])
157
+ s.add_development_dependency(%q<redcarpet>, ["= 1.17.2"])
158
+ s.add_development_dependency(%q<github-markup>, [">= 0"])
159
+ s.add_development_dependency(%q<pry>, [">= 0"])
160
+ s.add_development_dependency(%q<fake_dynamo>, [">= 0"])
161
+ s.add_development_dependency(%q<mocha>, ["= 0.10.0"])
162
+ else
163
+ s.add_dependency(%q<activemodel>, [">= 0"])
164
+ s.add_dependency(%q<tzinfo>, [">= 0"])
165
+ s.add_dependency(%q<aws-sdk>, [">= 0"])
166
+ s.add_dependency(%q<rake>, [">= 0"])
167
+ s.add_dependency(%q<rspec>, [">= 0"])
168
+ s.add_dependency(%q<bundler>, [">= 0"])
169
+ s.add_dependency(%q<jeweler>, [">= 0"])
170
+ s.add_dependency(%q<yard>, [">= 0"])
171
+ s.add_dependency(%q<redcarpet>, ["= 1.17.2"])
172
+ s.add_dependency(%q<github-markup>, [">= 0"])
173
+ s.add_dependency(%q<pry>, [">= 0"])
174
+ s.add_dependency(%q<fake_dynamo>, [">= 0"])
175
+ s.add_dependency(%q<mocha>, ["= 0.10.0"])
176
+ end
177
+ else
178
+ s.add_dependency(%q<activemodel>, [">= 0"])
179
+ s.add_dependency(%q<tzinfo>, [">= 0"])
180
+ s.add_dependency(%q<aws-sdk>, [">= 0"])
181
+ s.add_dependency(%q<rake>, [">= 0"])
182
+ s.add_dependency(%q<rspec>, [">= 0"])
183
+ s.add_dependency(%q<bundler>, [">= 0"])
184
+ s.add_dependency(%q<jeweler>, [">= 0"])
185
+ s.add_dependency(%q<yard>, [">= 0"])
186
+ s.add_dependency(%q<redcarpet>, ["= 1.17.2"])
187
+ s.add_dependency(%q<github-markup>, [">= 0"])
188
+ s.add_dependency(%q<pry>, [">= 0"])
189
+ s.add_dependency(%q<fake_dynamo>, [">= 0"])
190
+ s.add_dependency(%q<mocha>, ["= 0.10.0"])
191
+ end
192
+ end
193
+
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+ gem 'activemodel'
3
+ gem 'tzinfo'
4
+ gem 'aws-sdk'
5
+
6
+ # Add dependencies required to use your gem here.
7
+ # Example:
8
+ # gem "activesupport", ">= 2.3.5"
9
+
10
+ # Add dependencies to develop your gem here.
11
+ # Include everything needed to run rake, tests, features, etc.
12
+ group :development do
13
+ gem "rake"
14
+ gem "rspec"
15
+ gem "bundler"
16
+ gem "jeweler"
17
+ gem "yard"
18
+ gem "redcarpet", '1.17.2'
19
+ gem 'github-markup'
20
+ gem 'pry'
21
+ gem 'fake_dynamo'
22
+ gem "mocha", '0.10.0'
23
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.8)
5
+ activesupport (= 3.2.8)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.8)
8
+ i18n (~> 0.6)
9
+ multi_json (~> 1.0)
10
+ aws-sdk (1.6.4)
11
+ httparty (~> 0.7)
12
+ json (~> 1.4)
13
+ nokogiri (>= 1.4.4)
14
+ uuidtools (~> 2.1)
15
+ builder (3.0.0)
16
+ coderay (1.0.7)
17
+ diff-lcs (1.1.3)
18
+ fake_dynamo (0.0.9)
19
+ activesupport
20
+ json
21
+ sinatra
22
+ git (1.2.5)
23
+ github-markup (0.7.4)
24
+ httparty (0.8.3)
25
+ multi_json (~> 1.0)
26
+ multi_xml
27
+ i18n (0.6.0)
28
+ jeweler (1.8.4)
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ rake
32
+ rdoc
33
+ json (1.7.5)
34
+ metaclass (0.0.1)
35
+ method_source (0.8)
36
+ mocha (0.10.0)
37
+ metaclass (~> 0.0.1)
38
+ multi_json (1.3.6)
39
+ multi_xml (0.5.1)
40
+ nokogiri (1.5.5)
41
+ pry (0.9.10)
42
+ coderay (~> 1.0.5)
43
+ method_source (~> 0.8)
44
+ slop (~> 3.3.1)
45
+ rack (1.4.1)
46
+ rack-protection (1.2.0)
47
+ rack
48
+ rake (0.9.2.2)
49
+ rdoc (3.12)
50
+ json (~> 1.4)
51
+ redcarpet (1.17.2)
52
+ rspec (2.11.0)
53
+ rspec-core (~> 2.11.0)
54
+ rspec-expectations (~> 2.11.0)
55
+ rspec-mocks (~> 2.11.0)
56
+ rspec-core (2.11.1)
57
+ rspec-expectations (2.11.2)
58
+ diff-lcs (~> 1.1.3)
59
+ rspec-mocks (2.11.2)
60
+ sinatra (1.3.3)
61
+ rack (~> 1.3, >= 1.3.6)
62
+ rack-protection (~> 1.2)
63
+ tilt (~> 1.3, >= 1.3.3)
64
+ slop (3.3.2)
65
+ tilt (1.3.3)
66
+ tzinfo (0.3.33)
67
+ uuidtools (2.1.3)
68
+ yard (0.8.2.1)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ activemodel
75
+ aws-sdk
76
+ bundler
77
+ fake_dynamo
78
+ github-markup
79
+ jeweler
80
+ mocha (= 0.10.0)
81
+ pry
82
+ rake
83
+ redcarpet (= 1.17.2)
84
+ rspec
85
+ tzinfo
86
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Josh Symonds
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,265 @@
1
+ # Dynamoid
2
+
3
+ Dynamoid is an ORM for Amazon's DynamoDB for Ruby applications. It
4
+ provides similar functionality to ActiveRecord and improves on
5
+ Amazon's existing
6
+ [HashModel](http://docs.amazonwebservices.com/AWSRubySDK/latest/AWS/Record/HashModel.html)
7
+ by providing better searching tools and native association support.
8
+
9
+ DynamoDB is not like other document-based databases you might know, and is very different indeed from relational databases. It sacrifices anything beyond the simplest relational queries and transactional support to provide a fast, cost-efficient, and highly durable storage solution. If your database requires complicated relational queries and transaction support, then this modest Gem cannot provide them for you, and neither can DynamoDB. In those cases you would do better to look elsewhere for your database needs.
10
+
11
+ But if you want a fast, scalable, simple, easy-to-use database (and a Gem that supports it) then look no further!
12
+
13
+ ## Installation
14
+
15
+ Installing Dynamoid is pretty simple. First include the Gem in your Gemfile:
16
+
17
+ ```ruby
18
+ gem 'dynamoid'
19
+ ```
20
+
21
+ Then you need to initialize it to get it going. Put code similar to this somewhere (a Rails initializer would be a great place for this if you're using Rails):
22
+
23
+ ```ruby
24
+ Dynamoid.configure do |config|
25
+ # config.adapter = 'aws_sdk' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
26
+ # config.access_key = 'access_key' # If connecting to DynamoDB, your access key is required.
27
+ # config.secret_key = 'secret_key' # So is your secret key.
28
+ # config.endpoint = 'dynamodb.us-east-1.amazonaws.com' # Set the regional endpoint for DynamoDB.
29
+ config.namespace = "dynamoid_app_development" # To namespace tables created by Dynamoid from other tables you might have.
30
+ config.warn_on_scan = true # Output a warning to the logger when you perform a scan rather than a query on a table.
31
+ config.partitioning = true # Spread writes randomly across the database. See "partitioning" below for more.
32
+ config.partition_size = 200 # Determine the key space size that writes are randomly spread across.
33
+ config.read_capacity = 100 # Read capacity for your tables
34
+ config.write_capacity = 20 # Write capacity for your tables
35
+ end
36
+
37
+ ```
38
+
39
+ Once you have the configuration set up, you need to move on to making models.
40
+
41
+ ## Setup
42
+
43
+ You *must* include ```Dynamoid::Document``` in every Dynamoid model.
44
+
45
+ ```ruby
46
+ class User
47
+ include Dynamoid::Document
48
+
49
+ end
50
+ ```
51
+
52
+ ### Table
53
+
54
+ Dynamoid has some sensible defaults for you when you create a new table, including the table name and the primary key column. But you can change those if you like on table creation.
55
+
56
+ ```ruby
57
+ class User
58
+ include Dynamoid::Document
59
+
60
+ table :name => :awesome_users, :key => :user_id, :read_capacity => 400, :write_capacity => 400
61
+ end
62
+ ```
63
+
64
+ These fields will not change an existing table: so specifying a new read_capacity and write_capacity here only works correctly for entirely new tables. Similarly, while Dynamoid will look for a table named `awesome_users` in your namespace, it won't change any existing tables to use that name; and if it does find a table with the correct name, it won't change its hash key, which it expects will be user_id. If this table doesn't exist yet, however, Dynamoid will create it with these options.
65
+
66
+ ### Fields
67
+
68
+ You'll have to define all the fields on the model and the data type of each field. Every field on the object must be included here; if you miss any they'll be completely bypassed during DynamoDB's initialization and will not appear on the model objects.
69
+
70
+ By default, fields are assumed to be of type ```:string```. But you can also use ```:integer```, ```:float```, ```:set```, ```:array```, ```:datetime```, and ```:serialized```. You get magic columns of id (string), created_at (datetime), and updated_at (datetime) for free.
71
+
72
+ ```ruby
73
+ class User
74
+ include Dynamoid::Document
75
+
76
+ field :name
77
+ field :email
78
+ field :rank, :integer
79
+ field :number, :float
80
+ field :joined_at, :datetime
81
+ field :hash, :serialized
82
+
83
+ end
84
+ ```
85
+
86
+ ### Indexes
87
+
88
+ You can also define indexes on fields, combinations of fields, and one range field. Yes, only one range field: in DynamoDB tables can have at most one range index, so make good use of it! To make an index, just specify the fields you want it on, either single or in an array. If the entire index is a range, pass ```:range => true```. Otherwise, pass the attribute that will become the range key. The only range attributes you can use right now are integers, floats, and datetimes. If you pass a string as a range key likely DynamoDB will complain a lot.
89
+
90
+ ```ruby
91
+ class User
92
+ include Dynamoid::Document
93
+
94
+ ...
95
+
96
+ index :name
97
+ index :email
98
+ index [:name, :email]
99
+ index :created_at, :range => true
100
+ index :name, :range_key => :joined_at
101
+
102
+ end
103
+ ```
104
+
105
+ ### Associations
106
+
107
+ Just like in ActiveRecord (or your other favorite ORM), Dynamoid uses associations to create links between models.
108
+
109
+ The only supported associations (so far) are ```has_many```, ```has_one```, ```has_and_belongs_to_many```, and ```belongs_to```. Associations are very simple to create: just specify the type, the name, and then any options you'd like to pass to the association. If there's an inverse association either inferred or specified directly, Dynamoid will update both objects to point at each other.
110
+
111
+ ```ruby
112
+ class User
113
+ include Dynamoid::Document
114
+
115
+ ...
116
+
117
+ has_many :addresses
118
+ has_many :students, :class => User
119
+ belongs_to :teacher, :class_name => :user
120
+ belongs_to :group
121
+ has_one :role
122
+ has_and_belongs_to_many :friends, :inverse_of => :friending_users
123
+
124
+ end
125
+
126
+ class Address
127
+ include Dynamoid::Document
128
+
129
+ ...
130
+
131
+ belongs_to :address # Automatically links up with the user model
132
+
133
+ end
134
+ ```
135
+
136
+ Contrary to what you'd expect, association information is always contained on the object specifying the association, even if it seems like the association has a foreign key. This is a side effect of DynamoDB's structure: it's very difficult to find foreign keys without an index. Usually you won't find this to be a problem, but it does mean that association methods that build new models will not work correctly -- for example, ```user.addresses.new``` returns an address that is not associated to the user. We'll be correcting this soon.
137
+
138
+ ### Validations
139
+
140
+ Dynamoid bakes in ActiveModel validations, just like ActiveRecord does.
141
+
142
+ ```ruby
143
+ class User
144
+ include Dynamoid::Document
145
+
146
+ ...
147
+
148
+ validates_presence_of :name
149
+ validates_format_of :email, :with => /@/
150
+ end
151
+ ```
152
+
153
+ To see more usage and examples of ActiveModel validations, check out the [ActiveModel validation documentation](http://api.rubyonrails.org/classes/ActiveModel/Validations.html).
154
+
155
+ ### Callbacks
156
+
157
+ Dynamoid also employs ActiveModel callbacks. Right now, callbacks are defined on ```save```, ```update```, ```destroy```, which allows you to do ```before_``` or ```after_``` any of those.
158
+
159
+ ```ruby
160
+ class User
161
+ include Dynamoid::Document
162
+
163
+ ...
164
+
165
+ before_save :set_default_password
166
+ after_create :notify_friends
167
+ after_destroy :delete_addresses
168
+ end
169
+ ```
170
+
171
+ ## Usage
172
+
173
+ ### Object Creation
174
+
175
+ Dynamoid's syntax is generally very similar to ActiveRecord's. Making new objects is simple:
176
+
177
+ ```ruby
178
+ u = User.new(:name => 'Josh')
179
+ u.email = 'josh@joshsymonds.com'
180
+ u.save
181
+ ```
182
+
183
+ Save forces persistence to the datastore: a unique ID is also assigned, but it is a string and not an auto-incrementing number.
184
+
185
+ ```ruby
186
+ u.id # => "3a9f7216-4726-4aea-9fbc-8554ae9292cb"
187
+ ```
188
+
189
+ Along with persisting the model's attributes, indexes are automatically updated on save. To use associations, you use association methods very similar to ActiveRecord's:
190
+
191
+ ```ruby
192
+ address = u.addresses.create
193
+ address.city = 'Chicago'
194
+ address.save
195
+ ```
196
+
197
+ ### Querying
198
+
199
+ Querying can be done in one of three ways:
200
+
201
+ ```ruby
202
+ Address.find(address.id) # Find directly by ID.
203
+ Address.where(:city => 'Chicago').all # Find by any number of matching criteria... though presently only "where" is supported.
204
+ Address.find_by_city('Chicago') # The same as above, but using ActiveRecord's older syntax.
205
+ ```
206
+
207
+ And you can also query on associations:
208
+
209
+ ```ruby
210
+ u.addresses.where(:city => 'Chicago').all
211
+ ```
212
+
213
+ But keep in mind Dynamoid -- and document-based storage systems in general -- are not drop-in replacements for existing relational databases. The above query does not efficiently perform a conditional join, but instead finds all the user's addresses and naively filters them in Ruby. For large associations this is a performance hit compared to relational database engines.
214
+
215
+ You can also limit returned results, or select a record from which to start, to support pagination:
216
+
217
+ ```ruby
218
+ Address.limit(5).start(address) # Only 5 addresses.
219
+ ```
220
+
221
+ ### Consistent Reads
222
+
223
+ Querying supports consistent reading. By default, DynamoDB reads are eventually consistent: if you do a write and then a read immediately afterwards, the results of the previous write may not be reflected. If you need to do a consistent read (that is, you need to read the results of a write immediately) you can do so, but keep in mind that consistent reads are twice as expensive as regular reads for DynamoDB.
224
+
225
+ ```ruby
226
+ Address.find(address.id, :consistent_read => true) # Find an address, ensure the read is consistent.
227
+ Address.where(:city => 'Chicago').consistent.all # Find all addresses where the city is Chicago, with a consistent read.
228
+ ```
229
+
230
+ ### Range Finding
231
+
232
+ If you have a range index, Dynamoid provides a number of additional other convenience methods to make your life a little easier:
233
+
234
+ ```ruby
235
+ User.where("created_at.gt" => DateTime.now - 1.day).all
236
+ User.where("created_at.lt" => DateTime.now - 1.day).all
237
+ ```
238
+
239
+ It also supports .gte and .lte. Turning those into symbols and allowing a Rails SQL-style string syntax is in the works. You can only have one range argument per query, because of DynamoDB's inherent limitations, so use it sensibly!
240
+
241
+ ## Partitioning, Provisioning, and Performance
242
+
243
+ DynamoDB achieves much of its speed by relying on a random pattern of writes and reads: internally, hash keys are distributed across servers, and reading from two consecutive servers is much faster than reading from the same server twice. Of course, many of our applications request one key (like a commonly used role, a superuser, or a very popular product) much more frequently than other keys. In DynamoDB, this will result in lowered throughput and slower response times, and is a design pattern we should try to avoid.
244
+
245
+ Dynamoid attempts to obviate this problem transparently by employing a partitioning strategy to divide up keys randomly across DynamoDB's servers. Each ID is assigned an additional number (by default 0 to 199, but you can increase the partition size in Dynamoid's configuration) upon save; when read, all 200 hashes are retrieved simultaneously and the most recently updated one is returned to the application. This results in a significant net performance increase, and is usually invisible to the application itself. It does, however, bring up the important issue of provisioning your DynamoDB tables correctly.
246
+
247
+ When your read or write throughput exceed your table's allowed provisioning, DynamoDB will wait on connections until throughput is available again. This will appear as very, very slow requests and can be somewhat frustrating. Partitioning significantly increases the amount of throughput tables will experience; though DynamoDB will ignore keys that don't exist, if you have 20 partitioned keys representing one object, all will be retrieved every time the object is requested. Ensure that your tables are set up for this kind of throughput, or turn provisioning off, to make sure that DynamoDB doesn't throttle your requests.
248
+
249
+ ## Credits
250
+
251
+ Dynamoid borrows code, structure, and even its name very liberally from the truly amazing [Mongoid](https://github.com/mongoid/mongoid). Without Mongoid to crib from none of this would have been possible, and I hope they don't mind me reusing their very awesome ideas to make DynamoDB just as accessible to the Ruby world as MongoDB.
252
+
253
+ Also, without contributors the project wouldn't be nearly as awesome. So many thanks to:
254
+
255
+ * [Anantha Kumaran](https://github.com/ananthakumaran)
256
+ * [Jason Dew](https://github.com/jasondew)
257
+
258
+ ## Running the tests
259
+
260
+ Running the tests is fairly simple. In one window, run `fake_dynamo`, and in the other, use `rake`.
261
+
262
+ ## Copyright
263
+
264
+ Copyright (c) 2012 Josh Symonds. See LICENSE.txt for further details.
265
+