Class: ChDB::ResultSet
- Inherits:
-
Object
- Object
- ChDB::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/chdb/result_set.rb
Overview
The ResultSet object encapsulates the enumerability of a query’s output. It is a simple cursor over the data that the query returns. It will very rarely (if ever) be instantiated directly. Instead, clients should obtain a ResultSet instance via Statement#execute.
Direct Known Subclasses
Instance Method Summary collapse
-
#columns ⇒ Object
Returns the names of the columns returned by this result set.
- #each ⇒ Object
-
#each_hash ⇒ Object
Provides an internal iterator over the rows of the result set where each row is yielded as a hash.
- #eof? ⇒ Boolean
-
#initialize(db, stmt) ⇒ ResultSet
constructor
Create a new ResultSet attached to the given database, using the given sql text.
- #next ⇒ Object
-
#next_hash ⇒ Object
Return the next row as a hash.
Constructor Details
#initialize(db, stmt) ⇒ ResultSet
Create a new ResultSet attached to the given database, using the given sql text.
13 14 15 16 |
# File 'lib/chdb/result_set.rb', line 13 def initialize(db, stmt) @db = db @stmt = stmt end |
Instance Method Details
#columns ⇒ Object
Returns the names of the columns returned by this result set.
41 42 43 |
# File 'lib/chdb/result_set.rb', line 41 def columns @stmt.columns end |
#each ⇒ Object
26 27 28 29 30 |
# File 'lib/chdb/result_set.rb', line 26 def each while (node = self.next) yield node end end |
#each_hash ⇒ Object
Provides an internal iterator over the rows of the result set where each row is yielded as a hash.
34 35 36 37 38 |
# File 'lib/chdb/result_set.rb', line 34 def each_hash while (node = next_hash) yield node end end |
#eof? ⇒ Boolean
18 19 20 |
# File 'lib/chdb/result_set.rb', line 18 def eof? @stmt.done? end |
#next ⇒ Object
22 23 24 |
# File 'lib/chdb/result_set.rb', line 22 def next @stmt.step end |
#next_hash ⇒ Object
Return the next row as a hash
46 47 48 49 50 51 |
# File 'lib/chdb/result_set.rb', line 46 def next_hash row = @stmt.step return nil unless row @stmt.columns.zip(row).to_h end |