Class: Kiba::Plus::Destination::PgBulk

Inherits:
Object
  • Object
show all
Includes:
PgBulkUtils, Helper
Defined in:
lib/kiba/plus/destination/pg_bulk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#format_sql, #mysql2_connect_hash, #scheme

Constructor Details

#initialize(options = {}) ⇒ PgBulk

Returns a new instance of PgBulk.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kiba/plus/destination/pg_bulk.rb', line 8

def initialize(options = {})
  @options = options
  @options.assert_valid_keys(
    :connect_url,
    :schema,
    :table_name,
    :columns,
    :truncate,
    :incremental,
    :unique_by,
    :input_file,
    :ignore_input_file_header
  )
  @conn = PG.connect(connect_url)
  @conn.exec "SET search_path TO %s" % [ options[:schema] ] if options[:schema]
  init
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



6
7
8
# File 'lib/kiba/plus/destination/pg_bulk.rb', line 6

def conn
  @conn
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/kiba/plus/destination/pg_bulk.rb', line 6

def options
  @options
end

Instance Method Details

#closeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kiba/plus/destination/pg_bulk.rb', line 30

def close
  if incremental
    drop_staging_table
    create_staging_table
    copy_to_staging_table
    merge_to_target_table
    drop_staging_table
  else
    copy_to_target_table
  end
  @conn.close
  @conn = nil
end

#write(row) ⇒ Object



26
27
28
# File 'lib/kiba/plus/destination/pg_bulk.rb', line 26

def write(row)
  # blank!
end