Sha256: 5a9d560242608e42ec6157d1b0d3d827b0112502eff69bf08e0746a6b90b352c

Contents?: true

Size: 594 Bytes

Versions: 4

Compression:

Stored size: 594 Bytes

Contents

# frozen_string_literal: true

require 'table_saw/connection'

module TableSaw
  module Queries
    class TableColumns
      QUERY = <<~SQL
        select attname as colname
        from pg_catalog.pg_attribute
        where
                attrelid = $1::regclass
          and attnum > 0
          and attisdropped = false
        order by attnum
      SQL

      attr_reader :table

      def initialize(table)
        @table = table
      end

      def call
        TableSaw::Connection.with { |conn| conn.exec_params(QUERY, [table]) }.map { |r| r['colname'] }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
table_saw-0.3.0 lib/table_saw/queries/table_columns.rb
table_saw-0.2.1 lib/table_saw/queries/table_columns.rb
table_saw-0.2.0 lib/table_saw/queries/table_columns.rb
table_saw-0.1.0 lib/table_saw/queries/table_columns.rb