Sha256: 50268274d58700d15822bd2cb95f4777da47b5fef64bd773bf498a7499f6b857

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

ArJdbc::ConnectionMethods.module_eval do
  def sqlite3_connection(config)
    begin
      require 'jdbc/sqlite3'
      ::Jdbc::SQLite3.load_driver(:require) if defined?(::Jdbc::SQLite3.load_driver)
    rescue LoadError # assuming driver.jar is on the class-path
    end

    parse_sqlite3_config!(config)
    database = config[:database]
    database = '' if database == ':memory:'
    config[:url] ||= "jdbc:sqlite:#{database}"
    config[:driver] ||= defined?(::Jdbc::SQLite3.driver_name) ? ::Jdbc::SQLite3.driver_name : 'org.sqlite.JDBC'
    config[:adapter_spec] ||= ::ArJdbc::SQLite3
    config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)
    config[:connection_alive_sql] ||= 'SELECT 1'
    
    jdbc_connection(config)
  end
  alias_method :jdbcsqlite3_connection, :sqlite3_connection

  private
  
  def parse_sqlite3_config!(config)
    config[:database] ||= config[:dbfile]
    # Allow database path relative to RAILS_ROOT :
    if config[:database] != ':memory:' && defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
      rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
      config[:database] = File.expand_path(config[:database], rails_root.to_s)
    end
  end
  
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-jdbc-adapter-1.3.1 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.0 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.0.rc1 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.3.0.beta2 lib/arjdbc/sqlite3/connection_methods.rb