Sha256: a584d1e59573930d2d9e7dd575fae0c606d0ca4b30db86b98ca3b4d5eb84adbb

Contents?: true

Size: 904 Bytes

Versions: 22

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

module TableSaw
  module Queries
    class SerialSequences
      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

      SerialSequence = Struct.new(:name, :table, :column)

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
table_saw-3.1.0 lib/table_saw/queries/serial_sequences.rb
table_saw-3.0.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.10.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.9.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.8.1 lib/table_saw/queries/serial_sequences.rb
table_saw-2.8.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.7.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.6.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.5.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.4.3 lib/table_saw/queries/serial_sequences.rb
table_saw-2.4.2 lib/table_saw/queries/serial_sequences.rb
table_saw-2.4.1 lib/table_saw/queries/serial_sequences.rb
table_saw-2.4.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.3.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.2.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.1.0 lib/table_saw/queries/serial_sequences.rb
table_saw-2.0.0 lib/table_saw/queries/serial_sequences.rb
table_saw-1.3.0 lib/table_saw/queries/serial_sequences.rb
table_saw-1.2.0 lib/table_saw/queries/serial_sequences.rb
table_saw-1.1.0 lib/table_saw/queries/serial_sequences.rb