Sha256: b3c8c75e6d31219e01cfab7328e057245cb87000b87419539e1d2f7b0d84f6c2

Contents?: true

Size: 589 Bytes

Versions: 13

Compression:

Stored size: 589 Bytes

Contents

# frozen_string_literal: true

module TableSaw
  module Formats
    class Copy < TableSaw::Formats::Base
      def header
        "COPY #{table_name} (#{quoted_columns}) FROM STDIN;"
      end

      def footer
        ['\.', "\n"]
      end

      def dump_row(row)
        row
      end

      private

      def quoted_columns
        TableSaw.schema_cache.columns_hash(table_name)
          .each_key
          .map { |name| connection.quote_column_name(name) }
          .join(', ')
      end

      def connection
        TableSaw.schema_cache.connection
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
table_saw-3.0.0 lib/table_saw/formats/copy.rb
table_saw-2.10.0 lib/table_saw/formats/copy.rb
table_saw-2.9.0 lib/table_saw/formats/copy.rb
table_saw-2.8.1 lib/table_saw/formats/copy.rb
table_saw-2.8.0 lib/table_saw/formats/copy.rb
table_saw-2.7.0 lib/table_saw/formats/copy.rb
table_saw-2.6.0 lib/table_saw/formats/copy.rb
table_saw-2.5.0 lib/table_saw/formats/copy.rb
table_saw-2.4.3 lib/table_saw/formats/copy.rb
table_saw-2.4.2 lib/table_saw/formats/copy.rb
table_saw-2.4.1 lib/table_saw/formats/copy.rb
table_saw-2.4.0 lib/table_saw/formats/copy.rb
table_saw-2.3.0 lib/table_saw/formats/copy.rb