forked from thiagopradi/octopus
-
Notifications
You must be signed in to change notification settings - Fork 3
Sharding
tchandy edited this page Sep 14, 2010
·
7 revisions
Octopus allows you to do Database Sharding. This means you could send some queries to specific shards, or pick one shard, and use it as the default database for your application.
Sending a query to a specific shard:
#This will create a new user in "canada" shard User.using(:canada).create!(:name => 'oi')
The Api also allows dynamically change the shard:
#This will create a new user in "canada" shard User.using(:canada).using(:master).using(:canada).create!(:name => 'oi')
You could also pass a block to #using method, and #using method will send all queries inside the block to a specific shard:
#This will create a new user and a new client in "canada" shard User.using(:canada) do User.create(:name => "User") Client.create(:name => "Client") end
the using method is also available for User instances:
class User < ActiveRecord::Base def awesome_queries using(:canada) do User.create(:name => "teste") Dog.create(:name => "Xpto") end end end # This will create a new user and a new dog in the canada shard: u = User.new u.awesome_queries()
The shard could also be specify in the ActionController.
#TODO