Module: Dynomite
- Extended by:
- Core
- Defined in:
- lib/dynomite/item.rb,
lib/dynomite.rb,
lib/dynomite/errors.rb,
lib/dynomite/version.rb,
lib/dynomite/migration.rb,
lib/dynomite/reserved_words.rb
Overview
The modeling is ActiveRecord-ish but not exactly because DynamoDB is a different type of database.
Examples:
post = MyModel.new
post = post.replace(title: "test title")
post.attrs now contain a generaetd unique partition_key id. Usually the partition_key is ‘id’. You can set your own unique id also:
post = MyModel.new(id: "myid", title: "my title")
post.replace
Note that the replace method replaces the entire item, so you need to merge the attributes if you want to keep the other attributes.
post = MyModel.find("myid")
post.attrs = post.attrs.deep_merge("desc": "my desc") # keeps title field
post.replace
The convenience ‘attrs` method performs a deep_merge:
post = MyModel.find("myid")
post.attrs("desc": "my desc") # <= does a deep_merge
post.replace
Note, a race condition edge case can exist when several concurrent replace calls are happening. This is why the interface is called replace to emphasis that possibility. TODO: implement post.update with db.update_item in a Ruby-ish way.
Defined Under Namespace
Modules: Core, DbConfig, Errors, Log Classes: Erb, Item, Migration
Constant Summary collapse
- ATTRIBUTE_TYPES =
{ 'string' => 'S', 'number' => 'N', 'binary' => 'B', 's' => 'S', 'n' => 'N', 'b' => 'B', }
- VERSION =
"1.2.6"
- RESERVED_WORDS =
%w[ as_json attrs attributes delete columns find getter new_record param_name partition_key replace setter scan table_name ].freeze