module Rapids::Batch

Public Instance Methods

batch(&block) click to toggle source
# File lib/rapids/batch.rb, line 36
def batch(&block)
  @batch = DefineBatch.new
  @batch.instance_exec(&block) if block_given?
end
batch_create(collection,options = {}) click to toggle source
# File lib/rapids/batch.rb, line 26
def batch_create(collection,options = {})
  drop_batch_table_if_exists
  
  create_batch_table
  
  create_batch_trigger(options)
  
  batch_insert(collection,options)
end

Private Instance Methods

batch_insert(values,options) click to toggle source
# File lib/rapids/batch.rb, line 59
def batch_insert(values,options)
  insert_into = InsertInto.new(self,@batch,values,options)

  connection.execute(insert_into.to_sql)
end
batch_table_name() click to toggle source

TODO refactor this it duplicates what’s done in model_extensions.rb

# File lib/rapids/batch.rb, line 66
def batch_table_name
  "$#{table_name}_batch"
end
create_batch_table() click to toggle source
# File lib/rapids/batch.rb, line 47
def create_batch_table
  create_table = CreateTable.new(self,@batch)
  
  connection.execute(create_table.to_sql)
end
create_batch_trigger(options) click to toggle source
# File lib/rapids/batch.rb, line 53
def create_batch_trigger(options)
  create_trigger = CreateTrigger.new(self,@batch,options)

  connection.execute(create_trigger.to_sql)
end
drop_batch_table_if_exists() click to toggle source
# File lib/rapids/batch.rb, line 42
def drop_batch_table_if_exists
  drop_table_sql = "DROP TABLE IF EXISTS `#{batch_table_name}`"
  self.connection.execute(drop_table_sql)
end