Class: PgStream::Stream
- Inherits:
-
Object
- Object
- PgStream::Stream
- Defined in:
- lib/pg_stream/stream.rb
Instance Method Summary collapse
- #each_row {|@first_row| ... } ⇒ Object
- #headers ⇒ Object
-
#initialize(db_conn, body) ⇒ Stream
constructor
A new instance of Stream.
Constructor Details
#initialize(db_conn, body) ⇒ Stream
Returns a new instance of Stream.
3 4 5 6 7 |
# File 'lib/pg_stream/stream.rb', line 3 def initialize(db_conn, body) @db_conn = db_conn @db_conn.send_query(body) @db_conn.set_single_row_mode end |
Instance Method Details
#each_row {|@first_row| ... } ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pg_stream/stream.rb', line 13 def each_row(&block) headers # ensure that headers has been called so we have the first row return unless @first_row # dont yield any rows if the query returns no results yield(@first_row) loop do res = @db_conn.get_result || break res.check res.each_row do |row| yield(row) end end end |
#headers ⇒ Object
9 10 11 |
# File 'lib/pg_stream/stream.rb', line 9 def headers @headers ||= get_headers end |