A feature-rich and powerful Ruby ORM for Amazon DynamoDB, designed to provide a familiar ActiveRecord-like experience for Ruby applications.
- ActiveRecord-style DSL: Implements an interface and configuration similar to Rails' ActiveRecord.
- Querying & Persistence: Provides methods for finding, querying, and updating models.
- Advanced ORM Features: Supports associations, callbacks, validations, Dirty API, optimistic locking, and type casting.
- Additional Attribute Types: Supports types not natively provided by Amazon DynamoDB, such as
DateTime,Time, and more. - Transactions: Supports Amazon DynamoDB transactional operations.
Add Dynamoid to your Gemfile:
gem 'dynamoid'
Or install it using bundle:
bundle add dynamoid
Alternatively, you can install the gem manually:
gem install dynamoid
To define a model, include Dynamoid::Document and declare your fields. Dynamoid supports ActiveModel validations and automatic timestamps:
class User include Dynamoid::Document field :name # Type defaults to :string field :email field :age, :integer field :active, :boolean, default: true validates :name, presence: true validates :email, format: { with: /@/ } end
Once defined, you can interact with your models using a familiar API:
# Create and Save user = User.create(name: 'Josh', email: '[email protected]') # Find and Update user = User.where(email: '[email protected]').first user.update_attributes(age: 30) # Querying users = User.where(active: true).all.to_a
Minimal connection settings are required. You can configure Dynamoid in several ways, such as in config/initializers/dynamoid.rb (for Rails) or directly in your setup:
require 'dynamoid' Dynamoid.configure do |config| config.access_key = 'REPLACE_WITH_ACCESS_KEY_ID' config.secret_key = 'REPLACE_WITH_SECRET_ACCESS_KEY' config.region = 'REPLACE_WITH_REGION' # e.g. 'us-west-2' end
- API Reference: Comprehensive documentation for all classes and methods is available on API Reference.
- User Guides: For detailed overviews and usage examples of specific features, see the online User Guides.
Dynamoid relies on aws-sdk-dynamodb (AWS SDK v3) and activemodel (>= 4.2). It officially supports Ruby >= 2.3 and Rails >= 4.2.
Compatibility is tested against the following versions:
- Ruby: 2.3 - 4.0 (including JRuby 10.x)
- Rails: 4.2 - 8.1
We welcome contributions to Dynamoid! Please see our CONTRIBUTING.md guide for details on how to get started. Join us!
See SECURITY.md.
The gem is available as open source under the terms of
the MIT License .
See LICENSE for the official Copyright Notice.
Dynamoid was originally created in 2012 by Josh Symonds (original repository). Historical issues and discussions prior to the project's migration in 2015 can still be found in the legacy issue tracker.
Dynamoid borrows code, structure, and even its name very liberally from the truly amazing Mongoid. Without Mongoid to crib from none of this would have been possible, and I hope they don't mind me reusing their very awesome ideas to make Amazon DynamoDB just as accessible to the Ruby world as MongoDB.
Also, without contributors the project wouldn't be nearly as awesome. So many thanks to:
- Chris Hobbs
- Logan Bowers
- Lane LaRue
- Craig Heneveld
- Anantha Kumaran
- Jason Dew
- Luis Arias
- Stefan Neculai
- Philip White *
- Peeyush Kumar
- Sumanth Ravipati
- Pascal Corpet
- Brian Glusman *
- Peter Boling *
- Andrew Konchin *
* Current Maintainers