Class: Gcloud::Datastore::Dataset::QueryResults
- Inherits:
-
Array
- Object
- Array
- Gcloud::Datastore::Dataset::QueryResults
- Defined in:
- lib/gcloud/datastore/dataset/query_results.rb
Overview
QueryResults is a special case Array with additional values. A QueryResults object is returned from Dataset#run and contains the Entities from the query as well as the query’s cursor and more_results value.
entities = dataset.run query
entities.size #=> 3
entities.cursor #=> "c3VwZXJhd2Vzb21lIQ"
Please be cautious when treating the QueryResults as an Array. Many common Array methods will return a new Array instance.
entities = dataset.run query
entities.size #=> 3
entities.cursor #=> "c3VwZXJhd2Vzb21lIQ"
names = entities.map { |e| e.name }
names.size #=> 3
names.cursor #=> NoMethodError
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
The cursor of the QueryResults.
-
#more_results ⇒ Object
readonly
The state of the query after the current batch.
Instance Method Summary collapse
-
#initialize(arr = [], cursor = nil, more_results = nil) ⇒ QueryResults
constructor
Create a new QueryResults with an array of values.
-
#more_after_limit? ⇒ Boolean
Convenience method for determining id the more_results value is “MORE_RESULTS_AFTER_LIMIT”.
-
#no_more? ⇒ Boolean
Convenience method for determining id the more_results value is “NO_MORE_RESULTS”.
-
#not_finished? ⇒ Boolean
Convenience method for determining id the more_results value is “NOT_FINISHED”.
Constructor Details
#initialize(arr = [], cursor = nil, more_results = nil) ⇒ QueryResults
Create a new QueryResults with an array of values.
79 80 81 82 83 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 79 def initialize arr = [], cursor = nil, more_results = nil super arr @cursor = cursor @more_results = more_results end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
The cursor of the QueryResults.
41 42 43 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 41 def cursor @cursor end |
#more_results ⇒ Object (readonly)
The state of the query after the current batch.
Expected values are:
“MORE_RESULTS_AFTER_LIMIT”: “NOT_FINISHED”: “NO_MORE_RESULTS”:
51 52 53 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 51 def more_results @more_results end |
Instance Method Details
#more_after_limit? ⇒ Boolean
Convenience method for determining id the more_results value is “MORE_RESULTS_AFTER_LIMIT”
64 65 66 67 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 64 def more_after_limit? more_results == Proto.to_more_results_string( Proto::QueryResultBatch::MoreResultsType::MORE_RESULTS_AFTER_LIMIT) end |
#no_more? ⇒ Boolean
Convenience method for determining id the more_results value is “NO_MORE_RESULTS”
72 73 74 75 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 72 def no_more? more_results == Proto.to_more_results_string( Proto::QueryResultBatch::MoreResultsType::NO_MORE_RESULTS) end |
#not_finished? ⇒ Boolean
Convenience method for determining id the more_results value is “NOT_FINISHED”
56 57 58 59 |
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 56 def not_finished? more_results == Proto.to_more_results_string( Proto::QueryResultBatch::MoreResultsType::NOT_FINISHED) end |