Last active
January 25, 2017 02:04
-
-
Save exviva/6f3dd321dba7091d75b22f95324a7801 to your computer and use it in GitHub Desktop.
Shameless usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shameless usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RateStore.create_tables! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'shameless' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rates = Rate.where(hotel_id: 1, | |
room_type: '1 bed', | |
check_in_date: Date.today) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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