lib/duckdb/result.rb in duckdb-0.8.0 vs lib/duckdb/result.rb in duckdb-0.8.1

- old
+ new

@@ -40,14 +40,30 @@ ToRuby.default = :_to_string alias column_size column_count alias row_size row_count + def self.use_chunk_each=(val) + raise DuckDB::Error, 'chunk_each is not available. Install duckdb >= 0.8.0 and rerun `gem install duckdb`.' unless instance_methods.include?(:chunk_each) + + @use_chunk_each = val + end + + def self.use_chunk_each? + !!@use_chunk_each + end + def each - return to_enum { row_size } unless block_given? + if self.class.use_chunk_each? + return chunk_each unless block_given? - row_count.times do |row_index| - yield row(row_index) + chunk_each { |row| yield row } + else + return to_enum { row_size } unless block_given? + + row_count.times do |row_index| + yield row(row_index) + end end end def row(row_index) row = []