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
- #add_condition(*args) ⇒ Object
- #current_conjunction ⇒ Object
- #direct_subqueries ⇒ Object
- #fld(field_name) ⇒ Object
- #next_table_suffix ⇒ Object
- #subqueries_with_fasten(fasten) ⇒ Object
- #table_alias ⇒ Object
Instance Method Details
#add_condition(*args) ⇒ Object
41 42 43 44 45 46 47 48 |
# File '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_conjunction ⇒ Object
50 51 52 |
# File 'lib/card/query/abstract_query/query_helper.rb', line 50 def current_conjunction "AND" end |
#direct_subqueries ⇒ Object
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
37 38 39 |
# File 'lib/card/query/abstract_query/query_helper.rb', line 37 def fld field_name "#{table_alias}.#{field_name}" end |
#next_table_suffix ⇒ Object
31 32 33 34 35 |
# File '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 '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_alias ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File '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 |