Class: SugoiBulkInsert::Builder
- Inherits:
-
Object
- Object
- SugoiBulkInsert::Builder
- Defined in:
- lib/sugoi_bulk_insert.rb
Instance Method Summary collapse
- #column(name, value) ⇒ Object
- #fire ⇒ Object
-
#initialize(table_name:, count: 1000) {|_self| ... } ⇒ Builder
constructor
A new instance of Builder.
- #to_sql ⇒ Object
Constructor Details
#initialize(table_name:, count: 1000) {|_self| ... } ⇒ Builder
Returns a new instance of Builder.
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 |
#fire ⇒ Object
20 21 22 |
# File 'lib/sugoi_bulk_insert.rb', line 20 def fire ActiveRecord::Base.connection.execute(to_sql) end |
#to_sql ⇒ Object
24 25 26 |
# File 'lib/sugoi_bulk_insert.rb', line 24 def to_sql "INSERT INTO `#{@table_name}` (#{columns}) VALUES #{values}" end |