module Slaver::Connection::ClassMethods
Public Instance Methods
on(config_name)
click to toggle source
Public: Change database connection for next query WARNING: It'll change current DB connection until insert, select or execute methods call
config_name - String or Symbol, name of config_section
NOTE:
if config was not found: 1) On production throws ArgumentError 2) Uses default configuration for current environment
Exception safety:
throws ArgumentError if no configuration was found
Examples
SomeModel.on(:slave).create(…) SomeModel.on(:slave).where(…).first
It also can be chained with other 'on' methods SomeModel.on(:slave).on(:other).find_by(…)
Returns self
# File lib/slaver/connection.rb, line 39 def on(config_name) ScopeProxy.new(self, config_name) end
within(config_name) { || ... }
click to toggle source
Public: Changes model's connection to database temporarily to execute block.
config_name - String or Symbol, name of config_section
NOTE:
if config was not found: 1) On production throws ArgumentError 2) Uses default configuration for current environment
Exception safety:
throws ArgumentError if no configuration was found
Examples
SomeModel.within :test_slave do # do some computations here end It is also possible to nest database connection code SomeModel.within :slave do do some computations here SomeModel.within :slave2 do # some other computations go here end end
Returns noting
# File lib/slaver/connection.rb, line 72 def within(config_name) config_handler.run_with(self, config_name, pools_handler) { yield } end
Private Instance Methods
config_handler()
click to toggle source
# File lib/slaver/connection.rb, line 78 def config_handler ConfigHandler.instance end
pools_handler()
click to toggle source
# File lib/slaver/connection.rb, line 82 def pools_handler PoolsHandler.instance end