Dymos
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
- Fork it ( https://github.com/hoshina85/dymos/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request