Class: Mohair::Select
- Inherits:
-
Object
- Object
- Mohair::Select
- Defined in:
- lib/mohair/sql/select.rb
Instance Method Summary collapse
- #bucket ⇒ Object
- #build_columns(items) ⇒ Object
-
#initialize(tree) ⇒ Select
constructor
A new instance of Select.
- #mapper ⇒ Object
- #maybe_column(item) ⇒ Object
- #reducer ⇒ Object
Constructor Details
Instance Method Details
#bucket ⇒ Object
39 40 41 |
# File 'lib/mohair/sql/select.rb', line 39 def bucket @from.bucket end |
#build_columns(items) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mohair/sql/select.rb', line 13 def build_columns items reqs = [] if items.class == Array then items.each do |i| reqs << maybe_column(i[:item]) end elsif items.class == Hash then reqs << maybe_column(items[:item]) elsif items.to_s == "*" then reqs = :all end reqs end |
#mapper ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mohair/sql/select.rb', line 43 def mapper where = @where.to_js ## don't do 'select * from table group by col' if @select == :all then ERB.new(GetAllMapper).result(binding) elsif @group_by and @group_by.col then select = [] col = @group_by.col @select.each do |c| select << c.to_map_js end ERB.new(GroupByMapperTemplate).result(binding) else select = [] @select.each do |c| select << c.to_map_js end ERB.new(MapperTemplate).result(binding) end end |
#maybe_column(item) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mohair/sql/select.rb', line 27 def maybe_column item if item.class == Hash then if item[:function] then Function.new item else raise item end else Column.new item end end |
#reducer ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mohair/sql/select.rb', line 64 def reducer if @select == :all then return nil end if @group_by and @group_by.col then col = @group_by.col return ERB.new(GroupByReducerTemplate).result(binding) end @select.each do |c| if c.is_agg? then agg_init, agg_fun = c.to_reduce_js return ERB.new(ReducerTemplate).result(binding) end end return nil end |