Sha256: 3130f9aef269e6724ec62290671c063512944b5480b1ec90183df90f03574d7a

Contents?: true

Size: 484 Bytes

Versions: 3

Compression:

Stored size: 484 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: 2) { PG::Connection.new(TableSaw.configuration.connection) }
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
table_saw-1.1.0 lib/table_saw/connection.rb
table_saw-1.0.1 lib/table_saw/connection.rb
table_saw-1.0.0 lib/table_saw/connection.rb