Class: Kiba::Plus::Source::Pg
- Inherits:
-
Object
- Object
- Kiba::Plus::Source::Pg
- Includes:
- Helper
- Defined in:
- lib/kiba/plus/source/pg.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(options = {}) ⇒ Pg
constructor
A new instance of Pg.
Methods included from Helper
#format_sql, #mysql2_connect_hash, #scheme
Constructor Details
#initialize(options = {}) ⇒ Pg
Returns a new instance of Pg.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kiba/plus/source/pg.rb', line 15 def initialize( = {}) @options = @options.assert_valid_keys( :connect_url, :schema, :query, :stream, :process_bar ) @client = PG.connect(connect_url) @client.exec "SET search_path TO %s" % [ [:schema] ] if [:schema] end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/kiba/plus/source/pg.rb', line 13 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/kiba/plus/source/pg.rb', line 13 def @options end |
Instance Method Details
#each ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kiba/plus/source/pg.rb', line 28 def each Kiba::Plus.logger.info query if stream? # http://www.rubydoc.info/github/ged/ruby-pg/PG%2FConnection%3Aset_single_row_mode client.send_query(query) client.set_single_row_mode loop do res = client.get_result or break res.check res.each do |row| if yield(row) end end else results = client.query(query) results.each do |row| if yield(row) end end end |