Sha256: 686fecd86269cfffc35789642c52acaaa54ea93a5ef07f28269f8c8fcbf6b8ae

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

require_relative './sql_functions/common'

module Aggrobot
  module SQLFunctions

    autoload :MySQL,  File.expand_path('../sql_functions/mysql', __FILE__)
    autoload :PgSQL, File.expand_path('../sql_functions/pgsql', __FILE__)
    autoload :SQLite, File.expand_path('../sql_functions/sqlite', __FILE__)

    POSTGRES_ADAPTER_NAME = 'PostgreSQL'
    SQLITE_ADAPTER_NAME = 'SQLite'
    MYSQL_ADAPTER_NAME = 'Mysql2'

    def self.setup(precision = 2, adapter = ActiveRecord::Base.connection.adapter_name)
      extend Common
      self.precision = precision
      adapter_module = case adapter
                         when POSTGRES_ADAPTER_NAME then PgSQL
                         when MYSQL_ADAPTER_NAME then MySQL
                         when SQLITE_ADAPTER_NAME then SQLite
                    else
                      raise Exception.new "Database adaptor not supported: #{ActiveRecord::Base.connection.adapter_name}"
                    end
      extend adapter_module
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aggrobot-0.1.0 lib/aggrobot/sql_functions.rb