Module: Card::Query::AbstractQuery::QueryHelper

Included in:
Card::Query::AbstractQuery
Defined in:
lib/card/query/abstract_query/query_helper.rb

Overview

shared methods for queries

Instance Method Summary collapse

Instance Method Details

#add_condition(*args) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/card/query/abstract_query/query_helper.rb', line 39

def add_condition *args
  @conditions <<
    if args.size > 1
      [args.shift, Query::Value.new(args.shift, self)]
    else
      args[0]
    end
end

#current_conjunctionObject



48
49
50
# File 'lib/card/query/abstract_query/query_helper.rb', line 48

def current_conjunction
  "AND"
end

#direct_subqueriesObject



6
7
8
# File 'lib/card/query/abstract_query/query_helper.rb', line 6

def direct_subqueries
  subqueries_with_fasten :direct
end

#fld(field_name) ⇒ Object



35
36
37
# File 'lib/card/query/abstract_query/query_helper.rb', line 35

def fld field_name
  "#{table_alias}.#{field_name}"
end

#next_table_suffixObject



30
31
32
33
# File 'lib/card/query/abstract_query/query_helper.rb', line 30

def next_table_suffix
  return root.next_table_suffix unless root?
  @table_suffix = (@table_suffix || -1) + 1
end

#subqueries_with_fasten(fasten) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/card/query/abstract_query/query_helper.rb', line 10

def subqueries_with_fasten fasten
  list = []
  subqueries.each do |s|
    next unless Array.wrap(fasten).include? s.fasten
    list << s
    list += s.subqueries_with_fasten s.fasten
  end
  list
end

#table_aliasObject



20
21
22
23
24
25
26
27
28
# File 'lib/card/query/abstract_query/query_helper.rb', line 20

def table_alias
  @table_alias ||= begin
    if fasten == :direct
      @superquery.table_alias
    else
      "#{table_prefix}#{next_table_suffix}"
    end
  end
end