Class: Card::Query::CardQuery

Inherits:
AbstractQuery show all
Includes:
Conjunctions, FoundBy, Interpretation, MatchAttributes, Normalization, ReferenceAttributes, RelationalAttributes, Run, Sorting, Clause
Defined in:
card/lib/card/query/card_query.rb,
card/lib/card/query/card_query/run.rb,
card/lib/card/query/card_query/sorting.rb,
card/lib/card/query/card_query/found_by.rb,
card/lib/card/query/card_query/conjunctions.rb,
card/lib/card/query/card_query/normalization.rb,
card/lib/card/query/card_query/interpretation.rb,
card/lib/card/query/card_query/match_attributes.rb,
card/lib/card/query/card_query/reference_attributes.rb,
card/lib/card/query/card_query/relational_attributes.rb

Overview

interpret CQL queries, transform them into SQL, and run them.

Defined Under Namespace

Modules: Conjunctions, FoundBy, Interpretation, MatchAttributes, Normalization, ReferenceAttributes, RelationalAttributes, Run, Sorting

Constant Summary

Constants included from Sorting

Sorting::SORT_BY_ITEM_JOIN_MAP

Constants included from Interpretation

Interpretation::INTERPRET_METHOD

Instance Attribute Summary

Attributes inherited from AbstractQuery

#comment, #conditions, #conditions_on_join, #joins, #mods, #negate, #statement, #subqueries, #superquery, #vars

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conjunctions

#all, #any, #current_conjunction, #not

Methods included from Sorting

#count_sort_query, #count_subselect, #join_cards, #join_count_sort_query, #sort, #sort_by, #sort_by_count, #sort_by_count_referred_to, #sort_by_item_join, #sort_by_item_join_field, #sort_method_not_implemented

Methods included from Normalization

#clause_to_hash, #normalize_array_value, #normalize_clause, #normalize_string_value, #normalize_value, #string_value_from_var

Methods included from Interpretation

#bad_attribute!, #deprecated_attribute, #interpret, #interpret_as_content?, #interpret_as_modifier?, #interpret_attributes, #interpret_item, #interpret_modifier, #no_method_for_attribute_type, #relate, #relate_compound, #relate_multi_value

Methods included from FoundBy

#found_by

Methods included from ReferenceAttributes

define_reference_method, #member, #member_of

Methods included from RelationalAttributes

#created_by, #creator_of, #edited_by, #editor_of, #last_edited_by, #last_editor_of, #left, #left_plus, #part, #plus, #right, #right_plus, #type, #updated_by, #updater_of

Methods included from MatchAttributes

#complete, #match, #name_match

Methods included from Run

#alter_result, #alter_results?, #card_result, #count_result, #default_result, #fetch_or_instantiate, #id_result, #key_result, #large_list, #name_result, #process_name, #raw_result, #result_method, #return_list, #return_simple, #run, #run_sql, #simple_result?

Methods included from Clause

#connection, #quote, #safe_sql

Methods inherited from AbstractQuery

#context, #depth, #init_instance_vars, #init_query_vars, #interpret, #root, #root?, #sql, #subquery

Methods included from AbstractQuery::Tie

#fasten, #fasten_tie, #id_from_val, #inherit_fasten, #left_join?, #negate_join, #restrict, #super_conditions, #superfield, #tie, #tie_subquery, #tie_with_exist, #tie_with_in, #tie_with_join, #tie_with_join_args

Methods included from AbstractQuery::QueryHelper

#add_condition, #current_conjunction, #direct_subqueries, #fld, #next_table_suffix, #subqueries_with_fasten, #table_alias

Constructor Details

#initialize(statement, comment = nil) ⇒ CardQuery

Returns a new instance of CardQuery.



33
34
35
36
37
# File 'card/lib/card/query/card_query.rb', line 33

def initialize statement, comment=nil
  super statement
  @comment = comment || default_comment
  interpret @statement
end

Class Method Details

.viewable_sqlObject

By default a query returns card objects. This is accomplished by returning a card identifier from SQL and then hooking into our caching system (see Card::Fetch)



21
22
23
# File 'card/lib/card/query/card_query.rb', line 21

def self.viewable_sql
  Card::Query::SqlStatement.new.permission_conditions("cards")
end

Instance Method Details

#default_commentObject



39
40
41
42
43
# File 'card/lib/card/query/card_query.rb', line 39

def default_comment
  return if @superquery || !Card.config.sql_comments

  statement.to_s
end

#full?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'card/lib/card/query/card_query.rb', line 54

def full?
  !superquery && mods[:return] != "count"
end

#limitObject

Query Hierarchy @root, @subqueries, and @superquery are used to track a hierarchy of query objects. This nesting allows to find, for example, cards that link to cards that link to cards….



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

def limit
  mods[:limit].to_i
end

#tableObject



25
26
27
# File 'card/lib/card/query/card_query.rb', line 25

def table
  "cards"
end

#table_prefixObject



29
30
31
# File 'card/lib/card/query/card_query.rb', line 29

def table_prefix
  "c"
end