Sha256: 8a0892dbccac52977c690232a8d3ed65e030c73d45c673ff3b3460d54b1beb93

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 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 in this class
    # to execute each query that it contains.
    def initialize query_container
      @query_container = Array(query_container)
    end

    # Saves queries contained in query_container attributes into database.
    # Use the helper that ActiveRecord provides. 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

4 entries across 4 versions & 1 rubygems

Version Path
mass_insert-0.0.4 lib/mass_insert/query_execution.rb
mass_insert-0.0.3 lib/mass_insert/query_execution.rb
mass_insert-0.0.2 lib/mass_insert/query_execution.rb
mass_insert-0.0.1 lib/mass_insert/query_execution.rb