Module: Sequel::Rails

Defined in:
lib/sequel/rails.rb,
lib/sequel/rails/railtie.rb,
lib/sequel/rails/version.rb,
lib/sequel/rails/translation_support.rb,
lib/sequel/rails/railties/log_subscriber.rb,
lib/sequel/rails/railties/controller_runtime.rb

Defined Under Namespace

Modules: Railties, TranslationSupport Classes: Railtie

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.connect_to(config_name, opts = {}) ⇒ Object

Opens a database connection based on the given configuration name



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sequel/rails.rb', line 22

def self.connect_to config_name, opts = {}
  config = configurations.resolve(config_name).configuration_hash.dup
  config[:adapter] = "sqlite" if config[:adapter] == "sqlite3"
  config[:max_connections] ||= config.delete(:pool) if config[:pool]
  config[:pool_timeout] ||= config.delete(:timeout) / 1000 if config[:timeout]
  Dir.chdir ::Rails.root do
    ::Sequel.connect config, opts
  end.tap do |db|
    callback = ::Rails.application.config.sequel.after_connect
    callback.call(db) if callback.respond_to?(:call)
  end
end