Module: Bmg::Sql::SelectList

Includes:
Expr
Defined in:
lib/bmg/sql/nodes/select_list.rb

Constant Summary

Constants included from Expr

Expr::AND, Expr::AS, Expr::COMMA, Expr::DOT, Expr::EQUAL, Expr::EXISTS, Expr::FALSE, Expr::GREATER, Expr::GREATER_OR_EQUAL, Expr::IN, Expr::LEFT_PARENTHESE, Expr::LESS, Expr::LESS_OR_EQUAL, Expr::NOT, Expr::NOT_EQUAL, Expr::OR, Expr::QUOTE, Expr::RIGHT_PARENTHESE, Expr::SPACE, Expr::TRUE

Instance Method Summary collapse

Methods included from Expr

#each_child, #flatten, #group_by?, #join?, #limit_or_offset?, #order_by?, #ordering, #set_operator?, #with_insert, #with_push, #with_update

Instance Method Details

#desaliaser(for_predicate = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bmg/sql/nodes/select_list.rb', line 6

def desaliaser(for_predicate = false)
  ->(a){
    item = sexpr_body.find{|item| item.as_name.to_s == a.to_s }
    return nil unless left = item && item.left
    return left unless for_predicate
    case left.first
    when :literal
      Predicate::Grammar.sexpr([:literal, left.last])
    when :qualified_name
      Predicate::Grammar.sexpr([:qualified_identifier, left.qualifier.to_sym, left.as_name.to_sym])
    else
      raise "Unexpected select_item `#{left}`"
    end
  }
end

#has_computed_attributes?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/bmg/sql/nodes/select_list.rb', line 26

def has_computed_attributes?
  sexpr_body.any?{|item| item.is_computed? }
end

#is_table_dee?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/bmg/sql/nodes/select_list.rb', line 22

def is_table_dee?
  Builder::IS_TABLE_DEE == self
end

#knows?(as_name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/bmg/sql/nodes/select_list.rb', line 30

def knows?(as_name)
  find_child{|child| child.as_name == as_name }
end

#to_attr_listObject



34
35
36
# File 'lib/bmg/sql/nodes/select_list.rb', line 34

def to_attr_list
  sexpr_body.map{|a| a.as_name.to_sym }
end

#to_sql(buffer, dialect) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/bmg/sql/nodes/select_list.rb', line 38

def to_sql(buffer, dialect)
  sexpr_body.each_with_index do |item,index|
    buffer << COMMA << SPACE unless index == 0
    item.to_sql(buffer, dialect)
  end
  buffer
end