class Bmg::Sql::Processor

Constants

UnexpectedError

Attributes

builder[R]

Public Class Methods

new(builder) click to toggle source
# File lib/bmg/sql/processor.rb, line 8
def initialize(builder)
  @builder = builder
end

Public Instance Methods

on_except(sexpr)
Alias for: on_set_operator
on_intersect(sexpr)
Alias for: on_set_operator
on_select_exp(sexpr) click to toggle source
# File lib/bmg/sql/processor.rb, line 31
def on_select_exp(sexpr)
  sexpr.with_update(2, apply(sexpr[2]))
end
on_set_operator(sexpr) click to toggle source
# File lib/bmg/sql/processor.rb, line 22
def on_set_operator(sexpr)
  sexpr.each_with_index.map{|child,index|
    index <= 1 ? child : apply(child)
  }
end
Also aliased as: on_union, on_except, on_intersect
on_union(sexpr)
Alias for: on_set_operator
on_with_exp(sexpr) click to toggle source
# File lib/bmg/sql/processor.rb, line 13
def on_with_exp(sexpr)
  applied = apply(sexpr.select_exp)
  if applied.with_exp?
    merge_with_exps(sexpr, applied, applied.select_exp)
  else
    sexpr.with_update(-1, applied)
  end
end

Private Instance Methods

merge_with_exps(left, right, main) click to toggle source
# File lib/bmg/sql/processor.rb, line 37
def merge_with_exps(left, right, main)
  if left.with_exp? and right.with_exp?
    [ :with_exp,
      merge_with_specs(left.with_spec, right.with_spec),
      main ]
  elsif left.with_exp?
    left.with_update(-1, main)
  elsif right.with_exp?
    right.with_update(-1, main)
  else
    main
  end
end
merge_with_specs(left, right) click to toggle source
# File lib/bmg/sql/processor.rb, line 51
def merge_with_specs(left, right)
  hash = left.to_hash.merge(right.to_hash){|k,v1,v2|
    unless v1 == v2
      msg = "Unexpected different SQL expr: "
      msg << "`#{v1.inspect}` vs. `#{v2.inspect}`"
      raise UnexpectedError, msg
    end
    v1
  }
  hash.map{|(k,v)| builder.name_intro(k,v) }.unshift(:with_spec)
end
tautology() click to toggle source
# File lib/bmg/sql/processor.rb, line 63
def tautology
  Predicate::Factory.tautology
end