Class: PgConduit::QueryStream
- Inherits:
-
Object
- Object
- PgConduit::QueryStream
- Defined in:
- lib/pg_conduit/query_stream.rb
Overview
Execute a SQL query and provide the results as a stream
Instance Attribute Summary collapse
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Instance Method Summary collapse
-
#each_row {|Hash| ... } ⇒ Object
Execute query and yield each row.
-
#initialize(pool) ⇒ QueryStream
constructor
A new instance of QueryStream.
- #query(sql) ⇒ self
Constructor Details
#initialize(pool) ⇒ QueryStream
Returns a new instance of QueryStream.
16 17 18 |
# File 'lib/pg_conduit/query_stream.rb', line 16 def initialize(pool) @pool = pool end |
Instance Attribute Details
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
13 14 15 |
# File 'lib/pg_conduit/query_stream.rb', line 13 def sql @sql end |
Instance Method Details
#each_row {|Hash| ... } ⇒ Object
Execute query and yield each row
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pg_conduit/query_stream.rb', line 28 def each_row @pool.with do |conn| conn.send_query @sql conn.set_single_row_mode loop do res = conn.get_result break unless res res.check res.stream_each { |row| yield row } end end end |
#query(sql) ⇒ self
22 23 24 |
# File 'lib/pg_conduit/query_stream.rb', line 22 def query(sql) self.tap { @sql = sql } end |