Class: Ensql::ActiveRecordAdapter
- Inherits:
-
Object
- Object
- Ensql::ActiveRecordAdapter
- Extended by:
- Forwardable
- Includes:
- Adapter
- Defined in:
- lib/ensql/active_record_adapter.rb
Overview
Wraps an ActiveRecord connection pool to implement the Adapter interface for ActiveRecord. Requires an ActiveRecord connection to be configured and established. By default, uses the connection pool on ActiveRecord::Base. Other pools can be passed to the constructor.
Class Method Summary collapse
-
.pool(base = ActiveRecord::Base) ⇒ PoolWrapper
Wrap the raw connections from an Active Record connection pool.
Instance Method Summary collapse
-
#initialize(base = ActiveRecord::Base) ⇒ ActiveRecordAdapter
constructor
A new instance of ActiveRecordAdapter.
Methods included from Adapter
#fetch_first_column, #fetch_first_field, #fetch_first_row
Constructor Details
#initialize(base = ActiveRecord::Base) ⇒ ActiveRecordAdapter
Returns a new instance of ActiveRecordAdapter.
53 54 55 |
# File 'lib/ensql/active_record_adapter.rb', line 53 def initialize(base = ActiveRecord::Base) @base = base end |
Class Method Details
.pool(base = ActiveRecord::Base) ⇒ PoolWrapper
Wrap the raw connections from an Active Record connection pool. This allows us to safely checkout the underlying database connection for use in a database specific adapter.
Ensql.adapter = MySqliteAdapter.new(ActiveRecordAdapter.pool)
38 39 40 41 42 |
# File 'lib/ensql/active_record_adapter.rb', line 38 def self.pool(base = ActiveRecord::Base) PoolWrapper.new do |client_block| base.connection_pool.with_connection { |connection| client_block.call connection.raw_connection } end end |