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
5 6 7 8 9 10 11 12 |
# File 'lib/sql_runner/connection.rb', line 5 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
18 19 20 |
# File 'lib/sql_runner/connection.rb', line 18 def connect(connection_string) @connection_pool = Connection.call(connection_string) end |
#connection_pool ⇒ Object
26 27 28 |
# File 'lib/sql_runner/connection.rb', line 26 def connection_pool @connection_pool end |
#disconnect ⇒ Object
22 23 24 |
# File 'lib/sql_runner/connection.rb', line 22 def disconnect connection_pool&.shutdown(&:disconnect) && (@connection_pool = nil) end |
#with_connection(&block) ⇒ Object
14 15 16 |
# File 'lib/sql_runner/connection.rb', line 14 def with_connection(&block) connection_pool.with(&block) end |