Sha256: c62d5522255b23c41b71fb2b8dfb40329dfa23f95259dd3f57695835a6c37feb

Contents?: true

Size: 702 Bytes

Versions: 3

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

module SQLRunner
  module Connection
    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: connection_string
      )
    end

    def with_connection(&block)
      connection_pool.with(&block)
    end

    def connect(connection_string)
      @connection_pool = Connection.call(connection_string)
    end

    def disconnect
      connection_pool&.shutdown(&:disconnect) && (@connection_pool = nil)
    end

    def connection_pool
      @connection_pool
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sql_runner-0.4.1 lib/sql_runner/connection.rb
sql_runner-0.4.0 lib/sql_runner/connection.rb
sql_runner-0.3.0 lib/sql_runner/connection.rb