Class: Frodo::Query
- Inherits:
-
Object
- Object
- Frodo::Query
- Defined in:
- lib/frodo/query.rb,
lib/frodo/query/criteria.rb,
lib/frodo/query/in_batches.rb,
lib/frodo/query/criteria/date_functions.rb,
lib/frodo/query/criteria/lambda_operators.rb,
lib/frodo/query/criteria/string_functions.rb,
lib/frodo/query/criteria/geography_functions.rb,
lib/frodo/query/criteria/comparison_operators.rb
Overview
Frodo::Query provides the query interface for requesting Entities matching specific criteria from an Frodo::EntitySet. This class should not be instantiated directly, but can be. Normally you will access a Query by first asking for one from the Frodo::EntitySet you want to query.
Defined Under Namespace
Modules: InBatches Classes: Criteria
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#[](property) ⇒ Object
Instantiates an Frodo::Query::Criteria for the named property.
-
#count ⇒ Integer
Build a query to count of an entity set.
-
#entity_set ⇒ Frodo::EntitySet
private
The EntitySet for this query.
-
#expand(*associations) ⇒ self
Specify associations to expand in the result.
-
#find(key) ⇒ Object
Build a query to find an entity with the supplied key value.
-
#include_count ⇒ self
Add inline count criteria to query.
-
#initialize(entity_set, options = {}) ⇒ Query
constructor
Create a new Query for the provided EntitySet.
-
#limit(value) ⇒ self
Add limit criteria to query.
-
#order_by(*properties) ⇒ self
Specify properties to order the result by.
-
#params ⇒ Hash
The parameter hash for this query.
-
#search(term) ⇒ Object
Adds a fulltext search term to the query NOTE: May not be implemented by the service.
-
#select(*properties) ⇒ self
Specify properties to select within the result.
-
#service ⇒ Frodo::Service
private
The service for this query.
-
#skip(value) ⇒ self
Add skip criteria to query.
-
#to_s ⇒ String
Convert Query to string.
-
#where(criteria) ⇒ Object
Adds a filter criteria to the query.
Constructor Details
#initialize(entity_set, options = {}) ⇒ Query
Create a new Query for the provided EntitySet
15 16 17 18 19 |
# File 'lib/frodo/query.rb', line 15 def initialize(entity_set, = {}) @entity_set = entity_set = setup_empty_criteria_set end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/frodo/query.rb', line 10 def end |
Instance Method Details
#[](property) ⇒ Object
Instantiates an Frodo::Query::Criteria for the named property.
23 24 25 26 27 |
# File 'lib/frodo/query.rb', line 23 def [](property) property_instance = @entity_set.new_entity.get_property(property) property_instance = property if property_instance.nil? Frodo::Query::Criteria.new(property: property_instance) end |
#count ⇒ Integer
Build a query to count of an entity set
142 143 144 |
# File 'lib/frodo/query.rb', line 142 def count "#{entity_set.name}/$count" end |
#entity_set ⇒ Frodo::EntitySet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The EntitySet for this query.
149 150 151 |
# File 'lib/frodo/query.rb', line 149 def entity_set @entity_set end |
#expand(*associations) ⇒ self
Specify associations to expand in the result.
96 97 98 99 |
# File 'lib/frodo/query.rb', line 96 def (*associations) criteria_set[:expand] += associations self end |
#find(key) ⇒ Object
Build a query to find an entity with the supplied key value.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/frodo/query.rb', line 32 def find(key) entity = @entity_set.new_entity key_property = entity.get_property(entity.primary_key) key_property.value = key pathname = "#{entity_set.name}(#{key_property.url_value})" select_criteria = if list_criteria(:select) list_criteria(:select).map { |k, v| "#{k}=#{v}" }.join('&') end [pathname, select_criteria].compact.join('?') end |
#include_count ⇒ self
Add inline count criteria to query. Not Supported in CRM2011
128 129 130 131 |
# File 'lib/frodo/query.rb', line 128 def include_count criteria_set[:inline_count] = true self end |
#limit(value) ⇒ self
Add limit criteria to query.
120 121 122 123 |
# File 'lib/frodo/query.rb', line 120 def limit(value) criteria_set[:top] = value.to_i self end |
#order_by(*properties) ⇒ self
Specify properties to order the result by. Can use ‘desc’ like ‘Name desc’
88 89 90 91 |
# File 'lib/frodo/query.rb', line 88 def order_by(*properties) criteria_set[:orderby] += properties self end |
#params ⇒ Hash
The parameter hash for this query.
155 156 157 |
# File 'lib/frodo/query.rb', line 155 def params assemble_criteria || {} end |
#search(term) ⇒ Object
Adds a fulltext search term to the query NOTE: May not be implemented by the service
67 68 69 70 |
# File 'lib/frodo/query.rb', line 67 def search(term) criteria_set[:search] << term self end |
#select(*properties) ⇒ self
Specify properties to select within the result.
104 105 106 107 |
# File 'lib/frodo/query.rb', line 104 def select(*properties) criteria_set[:select] += properties self end |
#service ⇒ Frodo::Service
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The service for this query
162 163 164 |
# File 'lib/frodo/query.rb', line 162 def service @service ||= entity_set.service end |
#skip(value) ⇒ self
Add skip criteria to query.
112 113 114 115 |
# File 'lib/frodo/query.rb', line 112 def skip(value) criteria_set[:skip] = value.to_i self end |
#to_s ⇒ String
Convert Query to string.
135 136 137 138 |
# File 'lib/frodo/query.rb', line 135 def to_s criteria = params.map { |k, v| "#{k}=#{v}" }.join('&') [entity_set.name, params.any? ? criteria : nil].compact.join('?') end |
#where(criteria) ⇒ Object
Adds a filter criteria to the query. For filter syntax see msdn.microsoft.com/en-us/library/gg309461.aspx Syntax:
Property Operator Value
For example:
Name eq 'Customer Service'
Operators: eq, ne, gt, ge, lt, le, and, or, not
Value
can be 'null', can use single quotes
59 60 61 62 |
# File 'lib/frodo/query.rb', line 59 def where(criteria) criteria_set[:filter] << criteria self end |