Sha256: 8318675a03827b78393e7050250d8aa0ee925e819cf66be3140d8c76b9a2d543

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

module ThinkingSphinx
  class AbstractAdapter
    def initialize(model)
      @model = model
    end
    
    def setup
      # Deliberately blank - subclasses should do something though. Well, if
      # they need to.
    end
      
    def self.detect(model)
      case model.connection.class.name
      when "ActiveRecord::ConnectionAdapters::MysqlAdapter",
           "ActiveRecord::ConnectionAdapters::MysqlplusAdapter"
        ThinkingSphinx::MysqlAdapter.new model
      when "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter"
        ThinkingSphinx::PostgreSQLAdapter.new model
      when "ActiveRecord::ConnectionAdapters::JdbcAdapter"
        if model.connection.config[:adapter] == "jdbcmysql"
          ThinkingSphinx::MysqlAdapter.new model
        elsif model.connection.config[:adapter] == "jdbcpostgresql"
          ThinkingSphinx::PostgreSQLAdapter.new model
        else
          raise "Invalid Database Adapter: Sphinx only supports MySQL and PostgreSQL"
        end
      when "ActiveRecord::ConnectionAdapters::SQLite3Adapter"
        ThinkingSphinx::SQLite3Adapter.new model
      when "ActiveRecord::ConnectionAdapters::OracleAdapter",
           "ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter"
        ThinkingSphinx::OracleAdapter.new model
      else
        raise "Invalid Database Adapter: Sphinx only supports MySQL and PostgreSQL, not #{model.connection.class.name}"
      end
    end
    
    def quote_with_table(column)
      "#{@model.quoted_table_name}.#{@model.connection.quote_column_name(column)}"
    end
    
    def select_each(query)
      connection.select_all(query).each do |values|
        yield values
      end
    end
    
    protected
    
    def connection
      @connection ||= @model.connection
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ebeigarts-thinking-sphinx-1.1.21 lib/thinking_sphinx/adapters/abstract_adapter.rb
ebeigarts-thinking-sphinx-1.1.22 lib/thinking_sphinx/adapters/abstract_adapter.rb
ebeigarts-thinking-sphinx-1.2.10 lib/thinking_sphinx/adapters/abstract_adapter.rb