Skip to content

Instantly share code, notes, and snippets.

@exviva
Last active January 25, 2017 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exviva/6f3dd321dba7091d75b22f95324a7801 to your computer and use it in GitHub Desktop.
Save exviva/6f3dd321dba7091d75b22f95324a7801 to your computer and use it in GitHub Desktop.
Shameless usage
Shameless usage
RateStore.create_tables!
gem 'shameless'
rates = Rate.where(hotel_id: 1,
room_type: '1 bed',
check_in_date: Date.today)
# app/models/rate.rb
class Rate
RateStore.attach(self)
index do
integer :hotel_id
string :room_type
string :check_in_date
shard_on :hotel_id # required, values need to be numeric
end
end
# config/initializers/rate_store.rb
RateStore = Shameless::Store.new(:rate_store) do |c|
c.partition_urls = [
ENV['RATE_STORE_DATABASE_URL_0'],
ENV['RATE_STORE_DATABASE_URL_1']
]
# total number of shards across all partitions
c.shards_count = 512
end
# All index fields are required,
# the rest is the schemaless content
rate = Rate.put(hotel_id: 1,
room_type: '1 bed',
check_in_date: Date.today,
discount_type: 'geo',
net_price: 120.0) # potentially ~20 fields
rate[:hotel_id] # => 1
rate[:net_price] # => 120.0
rate.ref_key # => 0 # that's the version
rate[:net_price] = 130.0
rate.save
rate.ref_key # => 1
# Or:
rate.update(net_price: 140.0)
rate.ref_key # => 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment