Class: Multisert

Inherits:
Object
  • Object
show all
Defined in:
lib/multisert.rb,
lib/multisert/version.rb

Constant Summary collapse

MAX_BUFFER_COUNT_DEFAULT =
10_000
INSERT_OPERATION_DEFAULT =
'INSERT INTO'
VERSION =
"0.0.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Multisert

Returns a new instance of Multisert.



13
14
15
16
17
# File 'lib/multisert.rb', line 13

def initialize attrs = {}
  attrs.each do |attr, value|
    self.send "#{attr}=", value
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



5
6
7
# File 'lib/multisert.rb', line 5

def connection
  @connection
end

#databaseObject

Returns the value of attribute database.



5
6
7
# File 'lib/multisert.rb', line 5

def database
  @database
end

#fieldsObject

Returns the value of attribute fields.



5
6
7
# File 'lib/multisert.rb', line 5

def fields
  @fields
end

#insert_strategyObject

Returns the value of attribute insert_strategy.



5
6
7
# File 'lib/multisert.rb', line 5

def insert_strategy
  @insert_strategy
end

#max_buffer_countObject



42
43
44
# File 'lib/multisert.rb', line 42

def max_buffer_count
  @max_buffer_count || MAX_BUFFER_COUNT_DEFAULT
end

#tableObject

Returns the value of attribute table.



5
6
7
# File 'lib/multisert.rb', line 5

def table
  @table
end

Instance Method Details

#<<(entry) ⇒ Object



27
28
29
30
31
# File 'lib/multisert.rb', line 27

def << entry
  entries << entry
  write_buffer! if write_buffer?
  entry
end

#entriesObject



23
24
25
# File 'lib/multisert.rb', line 23

def entries
  buffer
end

#with_buffering {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Multisert)

    the object that the method was called on



46
47
48
49
# File 'lib/multisert.rb', line 46

def with_buffering &block
  yield self
  write_buffer!
end

#write_buffer!Object Also known as: write!, flush!



33
34
35
36
37
# File 'lib/multisert.rb', line 33

def write_buffer!
  return if buffer_empty?
  @connection.query multisert_sql
  reset_buffer!
end