Class: ChDB::ResultSet

Inherits:
Object
  • Object
show all
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

HashResultSet

Instance Method Summary collapse

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

#columnsObject

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

#eachObject



26
27
28
29
30
# File 'lib/chdb/result_set.rb', line 26

def each
  while (node = self.next)
    yield node
  end
end

#each_hashObject

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/chdb/result_set.rb', line 18

def eof?
  @stmt.done?
end

#nextObject



22
23
24
# File 'lib/chdb/result_set.rb', line 22

def next
  @stmt.step
end

#next_hashObject

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