Class: Kiba::Plus::Destination::Pg
- Inherits:
-
Object
- Object
- Kiba::Plus::Destination::Pg
- Defined in:
- lib/kiba/plus/destination/pg.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(options = {}) ⇒ Pg
constructor
A new instance of Pg.
- #write(row) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Pg
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kiba/plus/destination/pg.rb', line 12 def initialize( = {}) = .assert_valid_keys( :connect_url, :schema, :table_name, :columns ) @conn = PG.connect(connect_url) @conn.exec "SET search_path TO %s" % [ [:schema] ] if [:schema] init end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
10 11 12 |
# File 'lib/kiba/plus/destination/pg.rb', line 10 def conn @conn end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/kiba/plus/destination/pg.rb', line 10 def end |
Instance Method Details
#close ⇒ Object
35 36 37 38 |
# File 'lib/kiba/plus/destination/pg.rb', line 35 def close @conn.close @conn = nil end |
#write(row) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/kiba/plus/destination/pg.rb', line 25 def write(row) @conn.exec_prepared(prepare_name, row.values_at(*columns)) rescue PG::Error => ex Kiba::Plus.logger.error "ERROR for #{row}" Kiba::Plus.logger.error ex. # Maybe, write to db table or file raise ex end |