Sha256: f7f381ba5e6edc224c0639f9271c3e3f6e7e5af4ef2069a0604398a7028c546e

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

# Don't need to load native sqlite3 adapter
$LOADED_FEATURES << "active_record/connection_adapters/sqlite_adapter.rb"
$LOADED_FEATURES << "active_record/connection_adapters/sqlite3_adapter.rb"

class ActiveRecord::Base
  class << self
    def sqlite3_connection(config)
      require "arjdbc/sqlite3"

      parse_sqlite3_config!(config)
      database = config[:database]
      database = '' if database == ':memory:'
      config[:url] ||= "jdbc:sqlite:#{database}"
      config[:driver] ||= "org.sqlite.JDBC"
      config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
      jdbc_connection(config)
    end

    def parse_sqlite3_config!(config)
      config[:database] ||= config[:dbfile]

      # Allow database path relative to RAILS_ROOT, but only if
      # the database path is not the special path that tells
      # Sqlite to build a database only in memory.
      rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
      if rails_root_defined && ':memory:' != config[:database]
        rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
        config[:database] = File.expand_path(config[:database], rails_root)
      end
    end

    alias_method :jdbcsqlite3_connection, :sqlite3_connection
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
intentmedia-activerecord-jdbc-adapter-1.1.1.1 lib/arjdbc/sqlite3/connection_methods.rb
c3-activerecord-jdbc-adapter-1.1.3.1 lib/arjdbc/sqlite3/connection_methods.rb
c3-activerecord-jdbc-adapter-1.1.3 lib/arjdbc/sqlite3/connection_methods.rb
jashmenn-activerecord-jdbc-adapter-1.2.0.0 lib/arjdbc/sqlite3/connection_methods.rb
jashmenn-activerecord-jdbc-adapter-1.2.0 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.1.3 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.1.2 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.1.1 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.1.0 lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.0.3-java lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.0.2-java lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.0.1-java lib/arjdbc/sqlite3/connection_methods.rb
activerecord-jdbc-adapter-1.0.0-java lib/arjdbc/sqlite3/connection_methods.rb