Sha256: 0016f4012c7fabfe3d5af4c2e97344dd9e67e05ad792bf883446fef77eb86b50

Contents?: true

Size: 787 Bytes

Versions: 2

Compression:

Stored size: 787 Bytes

Contents

# frozen_string_literal: true

module Masking
  class InsertStatement
    class SQLBuilder
      class << self
        def build(table:, columns:, values:)
          new(table: table, columns: columns, values: values).send(:build)
        end
      end

      private

      attr_reader :table, :columns, :values
      def initialize(table:, columns:, values:)
        @table   = table
        @columns = columns
        @values  = values
      end

      def build
        %(INSERT INTO `#{table}` #{columns_section} VALUES #{values_section};\n)
      end

      def columns_section
        '(' + columns.map { |column| "`#{column}`" }.join(', ') + ')'
      end

      def values_section
        values.map { |value| '(' + value.join(',') + ')' }.join(',')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masking-1.0.0 lib/masking/insert_statement/sql_builder.rb
masking-0.0.3 lib/masking/insert_statement/sql_builder.rb