Class: MultiTenant::CopyFromClientHelper
- Inherits:
-
Object
- Object
- MultiTenant::CopyFromClientHelper
- Defined in:
- lib/activerecord-multi-tenant/copy_from_client.rb
Overview
Designed to be mixed into an ActiveRecord model to provide a copy_from_client method that allows for efficient bulk insertion of data into a PostgreSQL database using the COPY command
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #<<(row) ⇒ Object
-
#initialize(conn, column_types) ⇒ CopyFromClientHelper
constructor
A new instance of CopyFromClientHelper.
Constructor Details
#initialize(conn, column_types) ⇒ CopyFromClientHelper
Returns a new instance of CopyFromClientHelper.
8 9 10 11 12 |
# File 'lib/activerecord-multi-tenant/copy_from_client.rb', line 8 def initialize(conn, column_types) @count = 0 @conn = conn @column_types = column_types end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
6 7 8 |
# File 'lib/activerecord-multi-tenant/copy_from_client.rb', line 6 def count @count end |
Instance Method Details
#<<(row) ⇒ Object
14 15 16 17 18 |
# File 'lib/activerecord-multi-tenant/copy_from_client.rb', line 14 def <<(row) row = row.map.with_index { |val, idx| @column_types[idx].serialize(val) } @conn.put_copy_data(row) @count += 1 end |