Class: Remi::Loader::Postgres
- Inherits:
-
Remi::Loader
- Object
- Remi::Loader
- Remi::Loader::Postgres
- 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
Instance Method Summary collapse
-
#initialize(*args, **kargs, &block) ⇒ Postgres
constructor
A new instance of Postgres.
-
#load(data) ⇒ true
On success.
Methods included from DataSubject::Postgres
Methods inherited from Remi::Loader
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.
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 |