lib/duckdb/result.rb in duckdb-0.9.1 vs lib/duckdb/result.rb in duckdb-0.9.1.1

- old
+ new

@@ -23,44 +23,48 @@ # p row # end class Result include Enumerable - ToRuby = { + TO_METHODS = Hash.new(:_to_string).merge( 1 => :_to_boolean, 3 => :_to_smallint, 4 => :_to_integer, 5 => :_to_bigint, 10 => :_to_float, 11 => :_to_double, 16 => :_to_hugeint_internal, 18 => :_to_blob, 19 => :_to_decimal_internal - } + ).freeze - 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) + class << self + def new + raise DuckDB::Error, 'DuckDB::Result cannot be instantiated directly.' + end - @use_chunk_each = val - end + def 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) - def self.use_chunk_each? - !!@use_chunk_each + @use_chunk_each = val + end + + def use_chunk_each? + !!@use_chunk_each + end end def each if self.class.use_chunk_each? return chunk_each unless block_given? chunk_each { |row| yield row } else - warn('this `each` behavior will be deprecated in the future. set `Result.use_chunk_each = true` to use new `each` behavior.') + warn('this `each` behavior will be deprecated in the future. set `DuckDB::Result.use_chunk_each = true` to use new `each` behavior.') return to_enum { row_size } unless block_given? row_count.times do |row_index| yield row(row_index) end @@ -74,10 +78,10 @@ end row end def to_value(row_index, col_index) - send(ToRuby[_column_type(col_index)], row_index, col_index) + send(TO_METHODS[_column_type(col_index)], row_index, col_index) end def enum_dictionary_values(col_index) values = [] _enum_dictionary_size(col_index).times do |i|