Project

rom-dynamo

0.01
Low commit activity in last 3 years
A long-lived project that still receives updates
DynamoDB adapter for Ruby Object Mapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 13.0
>= 1.7
>= 4.0, < 9.0

Runtime

>= 1.0, < 6.0
 Project Readme

rom-dynamo

Gem Version Build Status

AWS DynamoDB adapter for ROM (Ruby Object Mapper).

Installation

gem 'rom-dynamo'

Usage

ROM-Dynamo uses the aws-sdk-dynamodb library. Configure AWS credentials before connecting:

Aws.config.merge!(
  credentials: Aws::Credentials.new(AWS_ACCESS, AWS_SECRET),
  region: 'us-east-1'
)

Connect using a URI that specifies the AWS region and an optional table name prefix:

dynamo://REGION/TABLE_PREFIX/

For example, with the URI below, accessing photos maps to the DynamoDB table myapp_photos in us-east-1 region:

dynamo://us-east-1/myapp_/

Relations

rom = ROM.container(:dynamo, 'dynamo://us-east-1/myapp_/') do |config|
  config.relation(:photos) do
    schema(infer: true)

    def by_id(id)
      restrict(id: id)
    end

    def all_for_user(user_id)
      index_restrict('user-to-id', user_id: user_id)
    end
  end
end

Repository

class PhotosRepo < ROM::Repository[:photos]
  commands :create, update: :by_id, delete: :by_id

  def by_id(id)
    photos.restrict(id: id).one
  end
end

repo = PhotosRepo.new(rom)
repo.create({ id: 1, user_id: 42, url: 'https://example.com/photo.jpg' })
repo.by_id(1)

Compatibility

  • Ruby >= 2.4 (MRI and JRuby)
  • ROM >= 5.0, < 6.0
  • aws-sdk-dynamodb ~> 1.0

Links

License

MIT