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



39
40
41
42
43
44
45
46
# File 'card/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 'card/lib/card/query/abstract_query/query_helper.rb', line 48

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



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

def fld field_name
  "#{table_alias}.#{field_name}"
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}#{root.table_seq}#{@table_suffix}"
    end
  end
end

#table_seqObject



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

def table_seq
  @table_seq = @table_seq ? (@table_seq + 1) : 0
end