Class: DataMapper::Adapters::Sqlite3Adapter

Inherits:
AbstractAdapter show all
Defined in:
lib/data_mapper/adapters/sqlite3_adapter.rb

Defined Under Namespace

Modules: Coersion, Queries

Constant Summary

Constants inherited from AbstractAdapter

AbstractAdapter::SYNTAX, AbstractAdapter::TYPES

Instance Method Summary collapse

Methods inherited from AbstractAdapter

inherited, #transaction

Constructor Details

#initialize(configuration) ⇒ Sqlite3Adapter

Returns a new instance of Sqlite3Adapter.



11
12
13
14
# File 'lib/data_mapper/adapters/sqlite3_adapter.rb', line 11

def initialize(configuration)
  super
  @connections = Support::ConnectionPool.new { Queries::Connection.new(@configuration)  }
end

Instance Method Details

#connectionObject

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/data_mapper/adapters/sqlite3_adapter.rb', line 16

def connection
  raise ArgumentError.new('Sqlite3Adapter#connection requires a block-parameter') unless block_given?
  begin
    @connections.hold { |connection| yield connection }
  rescue SQLite3::Exception => sle
    
    @configuration.log.fatal(sle)
    
    @connections.available_connections.each do |sock|
      begin
        sock.close
      rescue => se
        @configuration.log.error(se)
      end
    end
    
    @connections.available_connections.clear
    raise sle
  end
end