Sha256: bc08f126c963b8f731830149c73aae4a3090ecbcfc31a052993b954d98aeb41a

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module MassInsert
  # This class is responsible to execute the query string into the
  # database. Uses the ActiveRecord::Base.connection.execute functionality
  # to execute the query string directly.
  class QueryExecution

    attr_accessor :query_container

    # The query string is usually passed by params when the ProcessControl
    # class instances this class. The query can be a string or an array,
    # therefore to be sure that the query_container attribute is an array
    # the param passed to this class is converted to array. The query
    # container attribute will be iterated in execute method to execute
    # each query that it contains.
    def initialize query_container
      @query_container = Array(query_container)
    end

    # Saves queries contained in query_container attribute into database.
    # Use the helper that ActiveRecord provides. The query_container
    # attribute is iterated to save each query that it contains.
    def execute
      @query_container.each do |query|
        ActiveRecord::Base.connection.execute(query)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mass_insert-0.1.1 lib/mass_insert/query_execution.rb
mass_insert-0.1.0 lib/mass_insert/query_execution.rb