Class: Arel::SqlCompiler::Seamless_Database_PoolCompiler

Inherits:
GenericCompiler
  • Object
show all
Defined in:
lib/seamless_database_pool/arel_compiler.rb

Overview

Hook into arel to use the compiler used by the master connection.

Class Method Summary collapse

Class Method Details

.new(relation) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/seamless_database_pool/arel_compiler.rb', line 5

def self.new(relation)
  @compiler_classes ||= {}
  master_adapter = relation.engine.connection.master_connection.adapter_name
  compiler_class = @compiler_classes[master_adapter]
  unless compiler_class
    begin
      require "arel/engines/sql/compilers/#{master_adapter.downcase}_compiler"
    rescue LoadError
      begin
        # try to load an externally defined compiler, in case this adapter has defined the compiler on its own.
        require "#{master_adapter.downcase}/arel_compiler"
      rescue LoadError
        raise "#{master_adapter} is not supported by Arel."
      end
    end
    compiler_class = Arel::SqlCompiler.const_get("#{master_adapter}Compiler")
    @compiler_classes[master_adapter] = compiler_class
  end
  compiler_class.new(relation)
end