Class: NoSE::Backend::PreparedUpdate
Overview
An update prepared with a backend which is ready to execute
Instance Attribute Summary collapse
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#execute(update_settings, update_conditions) ⇒ void
Execute the statement for the given set of conditions.
-
#initialize(statement, support_plans, steps) ⇒ PreparedUpdate
constructor
A new instance of PreparedUpdate.
Constructor Details
#initialize(statement, support_plans, steps) ⇒ PreparedUpdate
Returns a new instance of PreparedUpdate.
402 403 404 405 406 407 408 409 410 411 |
# File 'lib/nose/backend.rb', line 402 def initialize(statement, support_plans, steps) @statement = statement @support_plans = support_plans @delete_step = steps.find do |step| step.is_a? Backend::DeleteStatementStep end @insert_step = steps.find do |step| step.is_a? Backend::InsertStatementStep end end |
Instance Attribute Details
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
400 401 402 |
# File 'lib/nose/backend.rb', line 400 def statement @statement end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
400 401 402 |
# File 'lib/nose/backend.rb', line 400 def steps @steps end |
Instance Method Details
#execute(update_settings, update_conditions) ⇒ void
This method returns an undefined value.
Execute the statement for the given set of conditions
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/nose/backend.rb', line 415 def execute(update_settings, update_conditions) # Execute all the support queries settings = initial_update_settings update_settings, update_conditions # Execute the support queries for this update support = support_results update_conditions # Perform the deletion @delete_step.process support unless support.empty? || @delete_step.nil? return if @insert_step.nil? # Get the fields which should be used from the original statement # If we didn't delete old entries, then we just need the primary key # attributes of the index, otherwise we need everything index = @insert_step.index include_fields = if @delete_step.nil? index.hash_fields + index.order_fields else index.all_fields end # Add fields from the original statement update_conditions.each_value do |condition| next unless include_fields.include? condition.field settings.merge! condition.field.id => condition.value end if support.empty? support = [settings] else support.each do |row| row.merge!(settings) { |_, value, _| value } end end # Stop if we have nothing to insert, otherwise insert return if support.empty? @insert_step.process support end |