Class: PostgresUpsert::ReadAdapters::ActiveRecordAdapter
- Inherits:
-
Object
- Object
- PostgresUpsert::ReadAdapters::ActiveRecordAdapter
- Defined in:
- lib/postgres_upsert/read_adapters/active_record_adapter.rb
Instance Method Summary collapse
- #columns ⇒ Object
- #continuous_write_enabled ⇒ Object
- #gets {|line| ... } ⇒ Object
-
#initialize(source, options) ⇒ ActiveRecordAdapter
constructor
A new instance of ActiveRecordAdapter.
- #sanitize_options(options) ⇒ Object
Constructor Details
#initialize(source, options) ⇒ ActiveRecordAdapter
Returns a new instance of ActiveRecordAdapter.
4 5 6 7 |
# File 'lib/postgres_upsert/read_adapters/active_record_adapter.rb', line 4 def initialize(source, ) @options = () @source = source end |
Instance Method Details
#columns ⇒ Object
32 33 34 |
# File 'lib/postgres_upsert/read_adapters/active_record_adapter.rb', line 32 def columns @source.column_names end |
#continuous_write_enabled ⇒ Object
15 16 17 |
# File 'lib/postgres_upsert/read_adapters/active_record_adapter.rb', line 15 def continuous_write_enabled false end |
#gets {|line| ... } ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/postgres_upsert/read_adapters/active_record_adapter.rb', line 19 def gets(&block) batch_size = 1_000 line = "" conn = @source.connection.raw_connection conn.copy_data("COPY #{@source.table_name} TO STDOUT") do while (line_read = conn.get_copy_data) do line << line_read end end yield line end |
#sanitize_options(options) ⇒ Object
9 10 11 12 13 |
# File 'lib/postgres_upsert/read_adapters/active_record_adapter.rb', line 9 def () .slice( :columns, :map, :unique_key ) end |