Class: TableSaw::Queries::TableColumns

Inherits:
Object
  • Object
show all
Defined in:
lib/table_saw/queries/table_columns.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ TableColumns

Returns a new instance of TableColumns.



18
19
20
# File 'lib/table_saw/queries/table_columns.rb', line 18

def initialize(table)
  @table = table
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



16
17
18
# File 'lib/table_saw/queries/table_columns.rb', line 16

def table
  @table
end

Instance Method Details

#callObject



22
23
24
# File 'lib/table_saw/queries/table_columns.rb', line 22

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