Sha256: 2269e59680bcb568a48e0d862a596bd5f6c6f2eb3b5a7f41709cbd04800f6290

Contents?: true

Size: 685 Bytes

Versions: 6

Compression:

Stored size: 685 Bytes

Contents

# frozen_string_literal: true

module TableSaw
  module Queries
    class ExecuteInsertStatement
      attr_reader :statement, :row

      def initialize(statement, row)
        @statement = statement
        @row = row
      end

      def call
        "EXECUTE #{statement.name}(#{values});"
      end

      private

      def values
        TableSaw.schema_cache.columns(statement.table_name).zip(row)
          .map { |column, value| connection.quote(connection.type_cast_from_column(column, value)) }
          .join(', ')
      end

      def schema_cache
        TableSaw.schema_cache
      end

      def connection
        schema_cache.connection
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
table_saw-2.5.0 lib/table_saw/queries/execute_insert_statement.rb
table_saw-2.4.3 lib/table_saw/queries/execute_insert_statement.rb
table_saw-2.4.2 lib/table_saw/queries/execute_insert_statement.rb
table_saw-2.4.1 lib/table_saw/queries/execute_insert_statement.rb
table_saw-2.4.0 lib/table_saw/queries/execute_insert_statement.rb
table_saw-2.3.0 lib/table_saw/queries/execute_insert_statement.rb