/dymos

Primary LanguageRubyMIT LicenseMIT

Dymos

Build Status Coverage Status

dynamodb model

Installation

Add this line to your application's Gemfile:

gem 'dymos'

install it yourself as:

$ gem install dymos

Usage

テーブル生成

Dymos::Query::CreateTable.name('ProductCatalogs')
  .attributes(category: 'S', title: 'S', ISBN:'S', price:'N')
  .keys(category: 'HASH', title: 'RANGE')
  .gsi([{name: 'global_index_isbn', keys: {ISBN: 'HASH'}, projection: {type: 'INCLUDE', attributes: [:title, :ISBN]}, throughput: {read: 20, write: 10}}])
  .lsi([{name: 'local_index_category_price', keys: {category: 'HASH', price: 'RANGE'}}])
  .throughput(read: 20, write: 10)

モデル定義

class Product < Dymos::Model
    table 'ProductCatalogs'
    field :category, :integer
    field :title, :string
    field :ISBN, :string
    field :price, :integer
    field :authors, :array
    field :created_at, :time
  end

クエリ

取得

Product.all
Product.find('Novels', 'The Catcher in the Rye') #key is category && title
Product.where(category:'Comics').all
Product.where(category:'Comics').add_filter(:authors,:contains,'John Smith').all
Product.where(category:'Comics').desc.one
Product.index(:local_index_category_price).add_condition(:category,'Comics')add_condition(:price,:gt,10000).all

保存

新規
product = Product.new(params)
product.save!
更新
product = Product.find(conditions)
product.price += 100
product.update!
product = Product.find(conditions)
product.add(price:100).put(authors:['Andy','Bob','Charlie']).update!

削除

product = Product.find(conditions)
product.add_expected(:price,10000).delete

Contributing

  1. Fork it ( https://github.com/hoshina85/dymos/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request