Sha256: dcb43a95f55f503c14f9c98fb7e6a2acb5278fb97066fad0dda7710cd656da32

Contents?: true

Size: 559 Bytes

Versions: 8

Compression:

Stored size: 559 Bytes

Contents

# frozen_string_literal: true

module TableSaw
  module Queries
    class PrimaryKeys
      QUERY = <<~SQL
        select tc.table_name, kcu.column_name
        from information_schema.table_constraints tc
                 join information_schema.key_column_usage kcu using (constraint_schema, constraint_name)
        where tc.constraint_type = 'PRIMARY KEY';
      SQL

      def call
        TableSaw::Connection.exec(QUERY).each_with_object({}) do |row, memo|
          memo[row['table_name']] = row['column_name']
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
table_saw-2.2.0 lib/table_saw/queries/primary_keys.rb
table_saw-2.1.0 lib/table_saw/queries/primary_keys.rb
table_saw-2.0.0 lib/table_saw/queries/primary_keys.rb
table_saw-1.3.0 lib/table_saw/queries/primary_keys.rb
table_saw-1.2.0 lib/table_saw/queries/primary_keys.rb
table_saw-1.1.0 lib/table_saw/queries/primary_keys.rb
table_saw-1.0.1 lib/table_saw/queries/primary_keys.rb
table_saw-1.0.0 lib/table_saw/queries/primary_keys.rb