Class: DbHelper
- Inherits:
-
Object
- Object
- DbHelper
- Defined in:
- lib/db_helper.rb
Instance Method Summary collapse
- #connect_db(config_or_url = @config.database_url) ⇒ Object
- #do_in_other_db(config_or_url) ⇒ Object
- #do_without_triggers ⇒ Object
-
#initialize(config) ⇒ DbHelper
constructor
A new instance of DbHelper.
Constructor Details
#initialize(config) ⇒ DbHelper
Returns a new instance of DbHelper.
4 5 6 7 |
# File 'lib/db_helper.rb', line 4 def initialize(config) @config = config connect_db end |
Instance Method Details
#connect_db(config_or_url = @config.database_url) ⇒ Object
9 10 11 |
# File 'lib/db_helper.rb', line 9 def connect_db(config_or_url=@config.database_url) ActiveRecord::Base.establish_connection(config_or_url) end |
#do_in_other_db(config_or_url) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/db_helper.rb', line 13 def do_in_other_db(config_or_url) saved_config = ActiveRecord::Base.connection_db_config connect_db(config_or_url) result = yield connect_db(saved_config) result end |
#do_without_triggers ⇒ Object
21 22 23 24 25 26 |
# File 'lib/db_helper.rb', line 21 def do_without_triggers ActiveRecord::Base.connection.execute('set session_replication_role = replica;') result = yield ActiveRecord::Base.connection.execute('set session_replication_role = default;') result end |