Class: Card::Query::CardQuery

Inherits:
AbstractQuery show all
Includes:
Conjunctions, Custom, 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/custom.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, Custom, 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

Constants inherited from AbstractQuery

AbstractQuery::ROOT_VAR_DEFAULTS

Instance Attribute Summary

Attributes inherited from AbstractQuery

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Custom

#compound

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 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

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, #seed_cache, #simple_result?

Methods included from Clause

#connection, #quote, #safe_sql

Methods inherited from AbstractQuery

#context, #depth, #interpret, #root, #root?, #sql, #sql_statement, #subquery

Methods included from AbstractQuery::Tie

#fasten, #fasten_tie, #id_from_val, #inherit_fasten, #left_join?, #list_of_ids?, #negate_join, #op_and_id_or_ids_from_val, #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, #subqueries_with_fasten, #table_alias, #table_seq

Constructor Details

#initialize(statement, comment = nil) ⇒ CardQuery

Returns a new instance of CardQuery.



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

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)



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

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

Instance Method Details

#default_commentObject



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

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

  statement.to_s
end

#full?Boolean

Returns:

  • (Boolean)


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

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….



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

def limit
  mods[:limit].to_i
end

#tableObject



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

def table
  "cards"
end

#table_prefixObject



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

def table_prefix
  "c"
end