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 ⇒ Object
Class Method Details
.call(connection_string) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/sql_runner/connection.rb', line 5 def self.call(connection_string) uri = URI.parse(connection_string) adapter = Adapters.find(uri.scheme) adapter.create_connection_pool( timeout: SQLRunner.timeout, size: SQLRunner.pool, connection_string: ) end |
Instance Method Details
#connect(connection_string) ⇒ Object
20 21 22 |
# File 'lib/sql_runner/connection.rb', line 20 def connect(connection_string) @connection_pool = Connection.call(connection_string) end |
#connection_pool ⇒ Object
28 29 30 |
# File 'lib/sql_runner/connection.rb', line 28 def connection_pool @connection_pool end |
#disconnect ⇒ Object
24 25 26 |
# File 'lib/sql_runner/connection.rb', line 24 def disconnect connection_pool&.shutdown(&:disconnect) && (@connection_pool = nil) end |
#with_connection ⇒ Object
16 17 18 |
# File 'lib/sql_runner/connection.rb', line 16 def with_connection(&) connection_pool.with(&) end |