Class: Sequel::Postgres::Dataset
- Inherits:
-
Object
- Object
- Sequel::Postgres::Dataset
- Defined in:
- lib/sequel_pg/sequel_pg.rb
Overview
Add faster versions of Dataset#map, #as_hash, #to_hash_groups, #select_map, #select_order_map, and #select_hash
Instance Method Summary collapse
-
#as_hash(key_column, value_column = nil, opts = Sequel::OPTS) ⇒ Object
(also: #to_hash)
In the case where both arguments given, use an optimized version.
-
#each ⇒ Object
If model loads are being optimized and this is a model load, use the optimized version.
-
#map(sym = nil) ⇒ Object
In the case where an argument is given, use an optimized version.
- #optimize_model_load ⇒ Object
- #optimize_model_load=(v) ⇒ Object
-
#to_hash_groups(key_column, value_column = nil, opts = Sequel::OPTS) ⇒ Object
In the case where both arguments given, use an optimized version.
-
#with_optimize_model_load(v) ⇒ Object
Return a modified copy with the optimize_model_load setting changed.
Instance Method Details
#as_hash(key_column, value_column = nil, opts = Sequel::OPTS) ⇒ Object Also known as: to_hash
In the case where both arguments given, use an optimized version.
45 46 47 48 49 50 51 52 53 |
# File 'lib/sequel_pg/sequel_pg.rb', line 45 def as_hash(key_column, value_column = nil, opts = Sequel::OPTS) if value_column && !opts[:hash] clone(:_sequel_pg_type=>:hash, :_sequel_pg_value=>[key_column, value_column]).fetch_rows(sql){|s| return s} elsif opts.empty? super(key_column, value_column) else super end end |
#each ⇒ Object
If model loads are being optimized and this is a model load, use the optimized version.
75 76 77 78 79 80 81 |
# File 'lib/sequel_pg/sequel_pg.rb', line 75 def each if optimize_model_load? clone(:_sequel_pg_type=>:model, :_sequel_pg_value=>row_proc).fetch_rows(sql, &Proc.new) else super end end |
#map(sym = nil) ⇒ Object
In the case where an argument is given, use an optimized version.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sequel_pg/sequel_pg.rb', line 25 def map(sym=nil) if sym if block_given? super else rows = [] clone(:_sequel_pg_type=>:map, :_sequel_pg_value=>sym).fetch_rows(sql){|s| rows << s} rows end else super end end |
#optimize_model_load ⇒ Object
19 20 21 22 |
# File 'lib/sequel_pg/sequel_pg.rb', line 19 def optimize_model_load Sequel::Deprecation.deprecate("Dataset#optimize_model_load method is deprecated. Optimized model loading is enabled by default.") opts.has_key?(:optimize_model_load) ? opts[:optimize_model_load] : true end |
#optimize_model_load=(v) ⇒ Object
15 16 17 18 |
# File 'lib/sequel_pg/sequel_pg.rb', line 15 def optimize_model_load=(v) Sequel::Deprecation.deprecate("Dataset#optimize_model_load= mutation method is deprecated. Switch to using Dataset#with_optimize_model_load, which returns a modified dataset") opts[:optimize_model_load] = v end |
#to_hash_groups(key_column, value_column = nil, opts = Sequel::OPTS) ⇒ Object
In the case where both arguments given, use an optimized version.
62 63 64 65 66 67 68 69 70 |
# File 'lib/sequel_pg/sequel_pg.rb', line 62 def to_hash_groups(key_column, value_column = nil, opts = Sequel::OPTS) if value_column && !opts[:hash] clone(:_sequel_pg_type=>:hash_groups, :_sequel_pg_value=>[key_column, value_column]).fetch_rows(sql){|s| return s} elsif opts.empty? super(key_column, value_column) else super end end |
#with_optimize_model_load(v) ⇒ Object
Return a modified copy with the optimize_model_load setting changed.
40 41 42 |
# File 'lib/sequel_pg/sequel_pg.rb', line 40 def with_optimize_model_load(v) clone(:optimize_model_load=>v) end |