A data mapping abstraction over the AWS SDK for Ruby’s client for Amazon
DynamoDB.
This library is currently under development. More features will be added as we
approach general availability, and while our initial release has as small of an
API surface area as possible, the interface may change before the GA release.
We would like to invite you to be a part of the ongoing development of this gem.
We welcome your contributions, and would also be happy to hear from you about
how you would like to use this gem. Feature requests are welcome.
Aws::Record is available as the aws-record gem from RubyGems.
gem install 'aws-record'
gem 'aws-record', '~> 2.0'
This automatically includes a dependency on the aws-sdk-dynamodb gem (part of the modular version-3 of
the AWS SDK for Ruby. If you need to pin to a specific version,
you can add aws-sdk-dynamodb
or aws-sdk-core gem in your
Gemfile.
Usage
To create a model that uses aws-record features, simply include the provided
module:
class MyModel
include Aws::Record
end
You can then specify attributes using the aws-record DSL:
class MyModel
include Aws::Record
integer_attr :id, hash_key: true
string_attr :name, range_key: true
boolean_attr :active, database_attribute_name: 'is_active_flag'
end
If a matching table does not exist in DynamoDB, you can use the TableConfig DSL to create your table:
cfg = Aws::Record::TableConfig.define do |t|
t.model_class(MyModel)
t.read_capacity_units(5)
t.write_capacity_units(2)
end
cfg.migrate!
With a table in place, you can then use your model class to manipulate items in
your table:
Aws Record models can be extended using standard ruby inheritance. The child model must
include Aws::Record in their model and the following will be inherited:
class Animal
include Aws::Record
string_attr :name, hash_key: true
integer_attr :age
end
class Dog < Animal
include Aws::Record
boolean_attr :family_friendly
end
dog = Dog.find(name: 'Sunflower')
dog.age = 3
dog.family_friendly = true
Aws::Record
A data mapping abstraction over the AWS SDK for Ruby’s client for Amazon DynamoDB.
This library is currently under development. More features will be added as we approach general availability, and while our initial release has as small of an API surface area as possible, the interface may change before the GA release.
We would like to invite you to be a part of the ongoing development of this gem. We welcome your contributions, and would also be happy to hear from you about how you would like to use this gem. Feature requests are welcome.
Table of Contents
Links of Interest
Installation
Aws::Recordis available as theaws-recordgem from RubyGems.This automatically includes a dependency on the
aws-sdk-dynamodbgem (part of the modular version-3 of the AWS SDK for Ruby. If you need to pin to a specific version, you can add aws-sdk-dynamodb or aws-sdk-core gem in your Gemfile.Usage
To create a model that uses
aws-recordfeatures, simply include the provided module:You can then specify attributes using the
aws-recordDSL:If a matching table does not exist in DynamoDB, you can use the TableConfig DSL to create your table:
With a table in place, you can then use your model class to manipulate items in your table:
Item Operations
You can use item operations on your model class to read and manipulate item(s).
More info under following documentation:
Example usage
BatchGetItemandBatchWriteItemAws Record provides BatchGetItem and BatchWriteItem support for aws-record models.
More info under the following documentation:
See examples below to see the feature in action.
BatchGetItemExampleBatchWriteItemExampleTransactions
Aws Record provides TransactGetItems and TransactWriteItems support for aws-record models.
More info under the Transactions documentation.
See examples below to see the feature in action.
TransactGetItemsExampleTransactWriteItemsExampleInheritance Support
Aws Record models can be extended using standard ruby inheritance. The child model must include
Aws::Recordin their model and the following will be inherited:See example below to see the feature in action.