Class: OData::Query
- Inherits:
-
Object
- Object
- OData::Query
- Defined in:
- lib/odata/query.rb,
lib/odata/query/result.rb,
lib/odata/query/criteria.rb
Overview
OData::Query provides the query interface for requesting Entities matching specific criteria from an OData::EntitySet. This class should not be instantiated directly, but can be. Normally you will access a Query by first asking for one from the OData::EntitySet you want to query.
Defined Under Namespace
Instance Method Summary collapse
-
#[](property) ⇒ Object
Instantiates an OData::Query::Criteria for the named property.
-
#count ⇒ Integer
Executes the query to get a count of entities.
-
#entity_set ⇒ OData::EntitySet
private
The EntitySet for this query.
-
#execute ⇒ OData::Query::Result
Execute the query.
-
#expand(*associations) ⇒ self
Specify associations to expand in the result.
-
#include_count ⇒ self
Add inline count criteria to query.
-
#initialize(entity_set) ⇒ 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.
-
#select(*properties) ⇒ self
Specify properties to select within the result.
-
#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) ⇒ Query
Create a new Query for the provided EntitySet
9 10 11 12 |
# File 'lib/odata/query.rb', line 9 def initialize(entity_set) @entity_set = entity_set setup_empty_criteria_set end |
Instance Method Details
#[](property) ⇒ Object
Instantiates an OData::Query::Criteria for the named property.
16 17 18 |
# File 'lib/odata/query.rb', line 16 def [](property) OData::Query::Criteria.new(property: property) end |
#count ⇒ Integer
Executes the query to get a count of entities.
101 102 103 |
# File 'lib/odata/query.rb', line 101 def count entity_set.service.execute("#{self.to_s}/$count").body.to_i end |
#entity_set ⇒ OData::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.
108 109 110 |
# File 'lib/odata/query.rb', line 108 def entity_set @entity_set end |
#execute ⇒ OData::Query::Result
Execute the query.
94 95 96 97 |
# File 'lib/odata/query.rb', line 94 def execute response = entity_set.service.execute(self.to_s) OData::Query::Result.new(self, response) end |
#expand(*associations) ⇒ self
Specify associations to expand in the result.
50 51 52 53 |
# File 'lib/odata/query.rb', line 50 def (*associations) criteria_set[:expand] += associations self end |
#include_count ⇒ self
Add inline count criteria to query.
81 82 83 84 |
# File 'lib/odata/query.rb', line 81 def include_count criteria_set[:inline_count] = true self end |
#limit(value) ⇒ self
Add limit criteria to query.
74 75 76 77 |
# File 'lib/odata/query.rb', line 74 def limit(value) criteria_set[:top] = value.to_i self end |
#order_by(*properties) ⇒ self
Specify properties to order the result by.
42 43 44 45 |
# File 'lib/odata/query.rb', line 42 def order_by(*properties) criteria_set[:orderby] += properties self end |
#select(*properties) ⇒ self
Specify properties to select within the result.
58 59 60 61 |
# File 'lib/odata/query.rb', line 58 def select(*properties) criteria_set[:select] += properties self end |
#skip(value) ⇒ self
Add skip criteria to query.
66 67 68 69 |
# File 'lib/odata/query.rb', line 66 def skip(value) criteria_set[:skip] = value.to_i self end |
#to_s ⇒ String
Convert Query to string.
88 89 90 |
# File 'lib/odata/query.rb', line 88 def to_s [entity_set.name, assemble_criteria].compact.join('?') end |
#where(criteria) ⇒ Object
Adds a filter criteria to the query.
22 23 24 25 |
# File 'lib/odata/query.rb', line 22 def where(criteria) criteria_set[:filter] << criteria self end |