Dinamo is an ORM for Dynamo DB, it has followed the behavior of the ORM which is often seen in the Ruby culture.
Add this line to your application's Gemfile:
gem 'dinamo'
And then execute:
$ bundle
Or install it yourself as:
$ gem install dinamo
Dinamo makes it easy to create DynamoDB record from any ruby object. Also, dinamo supports for data types of Dynamo DB such as scaler types, document types and set types. This means things that you can declare their types on your model.
Of course, you can use validations, casting and model change tracking smoothly. Next section will describe their things with example code.
class User < Dinamo::Model
hash_key :name, type: :string
field :age, type: :number
end
user = User.new(name: 'numb', age: 24)
user.persisted? #=> false
user.save
user.persisted? #=> true
Or you can use create
.
user = User.create(name: 'numb', age: 24)
user.persisted? #=> true
user = User.new(name: 'numb', age: 24)
user.changed? #=> false
user.age = 25
user.changed? #=> true
user.save
user.changed? #=> false
class NameLengthValidator < Dinamo::Model::Validation::Validator
def validate(record)
unless options[:length].include?(record.name.length)
record.errors.add(:name, I18n.t("models.user.error.length"))
end
end
end
class User < Dinamo::Model
hash_key :id
field :name, type: :string
validates_with NameLengthValidator, length: 1..30
end
Bug reports and pull requests are welcome on GitHub at https://github.com/namusyaka/dinamo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.