Class: SugoiBulkInsert::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/sugoi_bulk_insert.rb

Instance Method Summary collapse

Constructor Details

#initialize(table_name:, count: 1000) {|_self| ... } ⇒ Builder

Returns a new instance of Builder.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
# File 'lib/sugoi_bulk_insert.rb', line 9

def initialize(table_name: , count: 1000)
  @table_name = table_name
  @count = count
  @table_info = {}
  yield(self)
end

Instance Method Details

#column(name, value) ⇒ Object



16
17
18
# File 'lib/sugoi_bulk_insert.rb', line 16

def column(name, value)
  @table_info[name] = value
end

#fireObject



20
21
22
# File 'lib/sugoi_bulk_insert.rb', line 20

def fire
  ActiveRecord::Base.connection.execute(to_sql)
end

#to_sqlObject



24
25
26
# File 'lib/sugoi_bulk_insert.rb', line 24

def to_sql
  "INSERT INTO `#{@table_name}` (#{columns}) VALUES #{values}"
end