Module: ArrayKeys::DatasetExtensions
- Defined in:
- lib/sequel/array_keys.rb
Overview
The DatasetExtensions module provides extensions that modify a dataset to return Array tuples instead of Hash tuples.
Instance Method Summary collapse
-
#array_tuples_each(opts = nil, &block) ⇒ Object
Fetches a dataset’s records, converting each tuple into an array with keys.
-
#array_tuples_update_each_method ⇒ Object
Provides the corresponding behavior to Sequel::Dataset#update_each_method, using array tuples.
Instance Method Details
#array_tuples_each(opts = nil, &block) ⇒ Object
Fetches a dataset’s records, converting each tuple into an array with keys.
195 196 197 |
# File 'lib/sequel/array_keys.rb', line 195 def array_tuples_each(opts = nil, &block) fetch_rows(select_sql(opts)) {|h| block[Array.from_hash(h)]} end |
#array_tuples_update_each_method ⇒ Object
Provides the corresponding behavior to Sequel::Dataset#update_each_method, using array tuples.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/sequel/array_keys.rb', line 201 def array_tuples_update_each_method # warning: ugly code generation ahead if @row_proc && @transform class << self def each(opts = nil, &block) if opts && opts[:naked] fetch_rows(select_sql(opts)) {|r| block[transform_load(Array.from_hash(r))]} else fetch_rows(select_sql(opts)) {|r| block[@row_proc[transform_load(Array.from_hash(r))]]} end self end end elsif @row_proc class << self def each(opts = nil, &block) if opts && opts[:naked] fetch_rows(select_sql(opts)) {|r| block[Array.from_hash(r)]} else fetch_rows(select_sql(opts)) {|r| block[@row_proc[Array.from_hash(r)]]} end self end end elsif @transform class << self def each(opts = nil, &block) fetch_rows(select_sql(opts)) {|r| block[transform_load(Array.from_hash(r))]} self end end else class << self def each(opts = nil, &block) fetch_rows(select_sql(opts)) {|r| block[Array.from_hash(r)]} self end end end end |