Class: Remi::Loader::Postgres

Inherits:
Remi::Loader show all
Includes:
DataSubject::Postgres
Defined in:
lib/remi/data_subjects/postgres.rb

Overview

Postgres Loader VERY PRELIMINARY IMPLEMENTAtION - ONLY LOADS TO TEMP TABLES IT IS THEN UP TO THE USER TO DO ELT TO LOAD THE FINAL TABLE

Instance Attribute Summary

Attributes inherited from Remi::Loader

#context, #logger

Instance Method Summary collapse

Methods included from DataSubject::Postgres

#connection

Methods inherited from Remi::Loader

#autoload, #fields

Constructor Details

#initialize(*args, **kargs, &block) ⇒ Postgres

Returns a new instance of Postgres.



156
157
158
159
# File 'lib/remi/data_subjects/postgres.rb', line 156

def initialize(*args, **kargs, &block)
  super
  init_postgres_loader(*args, **kargs, &block)
end

Instance Method Details

#load(data) ⇒ true

Returns On success.

Parameters:

  • data (Encoder::Postgres)

    Data that has been encoded appropriately to be loaded into the target

Returns:

  • (true)

    On success



163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/remi/data_subjects/postgres.rb', line 163

def load(data)
  logger.info "Performing postgres load to table #{@table_name}"
  create_table_sql = "CREATE TEMPORARY TABLE #{@table_name} (#{data.ddl_fields})"
  logger.info create_table_sql
  connection.exec create_table_sql

  connection.copy_data "COPY #{@table_name} (#{data.fields.keys.join(', ')}) FROM STDIN" do
    data.values.each do |row|
      connection.put_copy_data "#{row}\n"
    end
  end

  true
end