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

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

Overview

shared methods for queries

Instance Method Summary collapse

Instance Method Details

#add_condition(*args) ⇒ Object



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

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

#current_conjunctionObject



50
51
52
# File 'card/lib/card/query/abstract_query/query_helper.rb', line 50

def current_conjunction
  "AND"
end

#direct_subqueriesObject



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

def direct_subqueries
  subqueries_with_fasten :direct
end

#fld(field_name) ⇒ Object



37
38
39
# File 'card/lib/card/query/abstract_query/query_helper.rb', line 37

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

#next_table_suffixObject



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

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
19
# File 'card/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



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

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