Module: SQLRunner::Connection
- Included in:
- Runner
- Defined in:
- lib/sql_runner/connection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connect(connection_string) ⇒ Object
- #connection_pool ⇒ Object
- #disconnect ⇒ Object
- #with_connection(&block) ⇒ Object
Class Method Details
.call(connection_string) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/sql_runner/connection.rb', line 3 def self.call(connection_string) uri = URI.parse(connection_string) adapter = Adapters.find(uri.scheme) ConnectionPool.new(timeout: SQLRunner.timeout, size: SQLRunner.pool) do adapter.new(connection_string) end end |
Instance Method Details
#connect(connection_string) ⇒ Object
16 17 18 |
# File 'lib/sql_runner/connection.rb', line 16 def connect(connection_string) @connection_pool = Connection.call(connection_string) end |
#connection_pool ⇒ Object
24 25 26 |
# File 'lib/sql_runner/connection.rb', line 24 def connection_pool @connection_pool end |
#disconnect ⇒ Object
20 21 22 |
# File 'lib/sql_runner/connection.rb', line 20 def disconnect connection_pool && connection_pool.shutdown {|conn| conn.disconnect } && (@connection_pool = nil) end |
#with_connection(&block) ⇒ Object
12 13 14 |
# File 'lib/sql_runner/connection.rb', line 12 def with_connection(&block) connection_pool.with(&block) end |