Class: TableSaw::Queries::SerialSequences

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

Defined Under Namespace

Classes: SerialSequence

Constant Summary collapse

QUERY =
<<~SQL
  select
    pg_get_serial_sequence(kcu.table_name, kcu.column_name) as sequence,
    kcu.table_name as table,
    kcu.column_name as column
  from information_schema.key_column_usage as kcu
           inner join information_schema.table_constraints as tc
                      on tc.constraint_name = kcu.constraint_name
  where tc.constraint_type = 'PRIMARY KEY'
    and pg_get_serial_sequence(kcu.table_name, kcu.column_name) is not null
SQL

Instance Method Summary collapse

Instance Method Details

#callObject



20
21
22
23
24
# File 'lib/table_saw/queries/serial_sequences.rb', line 20

def call
  TableSaw.connection.exec_query(QUERY).each_with_object({}) do |row, memo|
    memo[row['table']] = SerialSequence.new(row['sequence'], row['table'], row['column'])
  end
end