module Card::Query

Card::Query is for finding implicit lists (or counts of lists) of cards.

Search and Set cards use Card::Query to query the database, and it’s also frequently used directly in code.

Query “statements” (objects, really) are made in CQL (Card Query Language). Because CQL is used by Sharks, [the primary CQL Syntax documentation is on decko.org](decko.org/CQL_Syntax). Note that the examples there are in JSON, like Search card content, but statements in Card::Query are in ruby form.

In Decko’s current form, Card::Query generates and executes SQL statements. However, the SQL generation is largely (not yet fully) separated from the CQL statement interpretation.

The most common way to use Card::Query is as follows:

list_of_cards = Card::Query.run(statement)

This is equivalent to:

query = Card::Query.new(statement)
list_of_cards = query.run

Upon initiation, the query is interpreted, and the following key objects are populated:

Each condition is either a SQL-ready string (boo) or an Array in this form:

[field_string_or_sym, (Card::Value::Query object)]

Constants

CONJUNCTIONS
DEFAULT_ORDER_DIRS
MODIFIERS

“dir” is DEPRECATED in favor of sort_dir “sort” is DEPRECATED in favor of sort_by, except in cases where sort’s value is a hash

OPERATORS

Attributes

attributes[RW]

Public Class Methods

class_for(type) click to toggle source
# File lib/card/query.rb, line 107
def class_for type
  const_get "#{type.capitalize}Query"
end
new(statement, comment=nil) click to toggle source
# File lib/card/query.rb, line 99
def new statement, comment=nil
  Query::CardQuery.new statement, comment
end
run(statement, comment=nil) click to toggle source
# File lib/card/query.rb, line 103
def run statement, comment=nil
  new(statement, comment).run
end
safe_sql(txt) click to toggle source
# File lib/card/query.rb, line 111
def safe_sql txt
  txt = txt.to_s
  raise "CQL contains disallowed characters: #{txt}" if txt.match?(/[^\w\s*().,]/)

  txt
end