Class: Multisert
- Inherits:
-
Object
- Object
- Multisert
- 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
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#database ⇒ Object
Returns the value of attribute database.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#insert_strategy ⇒ Object
Returns the value of attribute insert_strategy.
- #max_buffer_count ⇒ Object
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #<<(entry) ⇒ Object
- #entries ⇒ Object
-
#initialize(attrs = {}) ⇒ Multisert
constructor
A new instance of Multisert.
- #with_buffering {|_self| ... } ⇒ Object
- #write_buffer! ⇒ Object (also: #write!, #flush!)
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
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/multisert.rb', line 5 def connection @connection end |
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/multisert.rb', line 5 def database @database end |
#fields ⇒ Object
Returns the value of attribute fields.
5 6 7 |
# File 'lib/multisert.rb', line 5 def fields @fields end |
#insert_strategy ⇒ Object
Returns the value of attribute insert_strategy.
5 6 7 |
# File 'lib/multisert.rb', line 5 def insert_strategy @insert_strategy end |
#max_buffer_count ⇒ Object
42 43 44 |
# File 'lib/multisert.rb', line 42 def max_buffer_count @max_buffer_count || MAX_BUFFER_COUNT_DEFAULT end |
#table ⇒ Object
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 |
#entries ⇒ Object
23 24 25 |
# File 'lib/multisert.rb', line 23 def entries buffer end |
#with_buffering {|_self| ... } ⇒ Object
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 |