Project

dinamo

0.01
No commit activity in last 3 years
No release in over 3 years
DynamoDB ORM for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Dinamo

build status gem license

Dinamo is an ORM for Dynamo DB, it has followed the behavior of the ORM which is often seen in the Ruby culture.

Installation

Add this line to your application's Gemfile:

gem 'dinamo'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dinamo

Overview

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.

Usage

Model definition

class User < Dinamo::Model
  hash_key :name, type: :string
  field    :age,  type: :number
end

Building/Saving

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

Dirty (model change tracking)

user = User.new(name: 'numb', age: 24)
user.changed? #=> false
user.age = 25
user.changed? #=> true
user.save
user.changed? #=> false

Validation

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

Contributing

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.

License

The gem is available as open source under the terms of the MIT License.