Git Product home page Git Product logo

dyna_model's Introduction

DynaModel

AWS DynamoDB ORM for Rails based on AWS::Record in the aws-sdk gem. Still a work in progress but very functional.

Installation

gem 'dyna_model'

Supports

  • Range Querying
  • Scans
  • Local Secondary Indexes
  • Global Secondary Indexes
  • Query Filtering

Sample Model

class Dude

  include DynaModel::Document
  
  string_attr :hashy
  integer_attr :ranger, default_value: 2
  string_attr :name, default_value: lambda { "dude" }
  boolean_attr :is_dude
  datetime_attr :born
  serialized_attr :cereal
  timestamps

  hash_key :hashy
  range_key :ranger

  set_shard_name "usery"

  local_secondary_index :name
  global_secondary_index(:name_index, { hash_key: :name, projection: [:name] })

  read_provision 4
  write_provision 4
  guid_delimiter "!"

  validates_presence_of :name
  
  before_create :do_something
  before_validation on: :create do
    do_something
  end

end

Sample Methods

# Read a single object by Hash and (optionally) Range keys
Dude.read

# Query by Hash and (optionally) Range keys (compatible with Local and Global Secondary Indexes)
Dude.read_range

# Batch read
Dude.read_multiple

# Read by guid (helper for hash + guid_delimiter + range)
Dude.read_guid

# Get count of query
Dude.count_range

# Table scan with more complex filters
Dude.scan

# Create Table
Dude.create_table

# Delete Table
Dude.delete_table

# Rake tasks
rake ddb:create CLASS=all
rake ddb:destroy CLASS=all
rake ddb:resize CLASS=all

Elasticsearch::Model compatible adapter

require 'dyna_model/adapters/elasticsearch/dyna_model_adapter'
class Item
  include DynaModel::Document
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks
end

CarrierWave compatible adapter

require "dyna_model/adapters/carrierwave/dyna_model"
class Item
  include DynaModel::Document
  mount_uploader :favicon, FaviconUploader
end

S3 Backup

Persist DynaModel records for a particular model to S3 for extra backup. Intended for incremental backups of important records and not intended for low value records or models with high frequency writes.

class Item
  include DynaModel::Document
  include DynaModel::Extensions::S3Backup
  
  dyna_model_s3_backup bucket: "dyna_model_backups", prefix: "items"
  
  # dyna_model_s3_backup bucket: "dyna_model_backups", prefix: "items", after_save: lambda { |item|
  #   Item.delay.dyna_model_s3_backup_object(item.dynamo_db_guid) # sidekiq write
  # }
end

AWS::Record

dyna_model's People

Contributors

cdunn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.