Sha256: bcde1c9515f8a66954f06569f817321a2b91ae7cfac94a9744796b7cab224238

Contents?: true

Size: 952 Bytes

Versions: 73

Compression:

Stored size: 952 Bytes

Contents

# frozen_string_literal: true

module Arel # :nodoc: all
  class InsertManager < Arel::TreeManager
    def initialize
      super
      @ast = Nodes::InsertStatement.new
    end

    def into(table)
      @ast.relation = table
      self
    end

    def columns; @ast.columns end
    def values=(val); @ast.values = val; end

    def select(select)
      @ast.select = select
    end

    def insert(fields)
      return if fields.empty?

      if String === fields
        @ast.values = Nodes::SqlLiteral.new(fields)
      else
        @ast.relation ||= fields.first.first.relation

        values = []

        fields.each do |column, value|
          @ast.columns << column
          values << value
        end
        @ast.values = create_values(values)
      end
      self
    end

    def create_values(values)
      Nodes::ValuesList.new([values])
    end

    def create_values_list(rows)
      Nodes::ValuesList.new(rows)
    end
  end
end

Version data entries

73 entries across 73 versions & 7 rubygems

Version Path
activerecord-6.1.7.10 lib/arel/insert_manager.rb
activerecord-6.1.7.9 lib/arel/insert_manager.rb
activerecord-6.1.7.8 lib/arel/insert_manager.rb
activerecord-6.1.7.7 lib/arel/insert_manager.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/arel/insert_manager.rb
activerecord-6.1.7.6 lib/arel/insert_manager.rb
activerecord-6.1.7.5 lib/arel/insert_manager.rb
activerecord-6.1.7.4 lib/arel/insert_manager.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/arel/insert_manager.rb
activerecord-6.1.7.3 lib/arel/insert_manager.rb
activerecord-6.1.7.2 lib/arel/insert_manager.rb
activerecord-6.1.7.1 lib/arel/insert_manager.rb
activerecord-6.0.6.1 lib/arel/insert_manager.rb
activerecord-6.1.7 lib/arel/insert_manager.rb
activerecord-6.0.6 lib/arel/insert_manager.rb
activerecord-6.1.6.1 lib/arel/insert_manager.rb
activerecord-6.0.5.1 lib/arel/insert_manager.rb
activerecord-6.0.5 lib/arel/insert_manager.rb
activerecord-6.1.6 lib/arel/insert_manager.rb
activerecord-6.1.5.1 lib/arel/insert_manager.rb