Skip to content

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.

License

Notifications You must be signed in to change notification settings

aws/aws-record-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

472feaa · Oct 12, 2022
Jul 26, 2021
Jun 14, 2021
Oct 12, 2022
Oct 12, 2022
Oct 12, 2022
Aug 10, 2021
Oct 12, 2022
May 27, 2020
Jul 29, 2020
Oct 12, 2022
Mar 28, 2018
Jul 27, 2021
Jul 26, 2021
Jul 30, 2020
Jul 30, 2020
Mar 8, 2021
Nov 12, 2020
Oct 12, 2022
Jul 30, 2020

Repository files navigation

Aws::Record

Build Status Code Climate Coverage Status

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.

Links of Interest

Installation

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:

item = MyModel.find(id: 1, name: "Hello Record")
item.active = true
item.save
item.delete!

MyModel.find(id: 1, name: "Hello Record") # => nil

item = MyModel.new
item.id = 2
item.name = "Item"
item.active = false
item.save