Sha256: 4ddd053e2f67159fac044eaf0cd55f1f97faca614181d84454964a5f7332fc97

Contents?: true

Size: 532 Bytes

Versions: 1

Compression:

Stored size: 532 Bytes

Contents

# frozen_string_literal: true

require 'pg'
require 'connection_pool'

module TableSaw
  module Connection
    def self.with
      raise ArgumentError, 'requires a block' unless block_given?

      pool.with { |conn| yield conn }
    end

    def self.pool
      @pool ||= ConnectionPool.new(size: TableSaw.configuration.pool_size) do
        PG::Connection.new(TableSaw.configuration.connection)
      end
    end

    def self.exec(sql)
      TableSaw::Connection.with do |conn|
        conn.exec(sql)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
table_saw-1.2.0 lib/table_saw/connection.rb