Module: DynamodbModel

Extended by:
Util
Defined in:
lib/dynamodb_model/item.rb,
lib/dynamodb_model.rb,
lib/dynamodb_model/version.rb,
lib/dynamodb_model/migration.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: DbConfig, Util Classes: Erb, Item, Migration

Constant Summary collapse

ATTRIBUTE_TYPES =
{
  'string' => 'S',
  'number' => 'N',
  'binary' => 'B',
  's' => 'S',
  'n' => 'N',
  'b' => 'B',
}
VERSION =
"1.0.1"

Method Summary

Methods included from Util

app_root