Class: Purview::Loaders::Base

Inherits:
Object
  • Object
show all
Includes:
Mixins::Dialect, Mixins::Helpers, Mixins::Logger
Defined in:
lib/purview/loaders/base.rb

Direct Known Subclasses

MSSQL, MySQL, PostgreSQL, SQLite

Instance Method Summary collapse

Methods included from Mixins::Logger

#logger, #logger_opts, #logger_type, #with_context_logging

Methods included from Mixins::Helpers

#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #timestamp, #with_timestamp, #zero?

Methods included from Mixins::Dialect

#dialect, #false_value, #null_value, #quoted, #sanitized, #true_value

Constructor Details

#initialize(opts = {}) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/purview/loaders/base.rb', line 4

def initialize(opts={})
  @opts = opts
end

Instance Method Details

#load(connection, rows, window) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/purview/loaders/base.rb', line 8

def load(connection, rows, window)
  with_context_logging("`load` for: #{table.name}") do
    with_temporary_table(connection, rows, window) do |temporary_table_name|
      update_result = \
        connection.execute(table_update_sql(window, temporary_table_name))
      delete_result = \
        connection.execute(table_delete_sql(window, temporary_table_name))
      insert_result = \
        connection.execute(table_insert_sql(window, temporary_table_name))
      logger.debug(
        '%d row(s) inserted, %d row(s) updated and %d row(s) deleted in: %s' % [
          insert_result.rows_affected,
          update_result.rows_affected,
          delete_result.rows_affected,
          table.name,
        ]
      )
    end
  end
end