Class: Gcloud::Datastore::Dataset::QueryResults

Inherits:
Array
  • Object
show all
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.

Please be cautious when treating the QueryResults as an Array. Many common Array methods will return a new Array instance.

Examples:

entities = dataset.run query
entities.size #=> 3
entities.cursor #=> "c3VwZXJhd2Vzb21lIQ"

Caution, many Array methods will return a new Array instance:

entities = dataset.run query
entities.size #=> 3
entities.end_cursor #=> "c3VwZXJhd2Vzb21lIQ"
names = entities.map { |e| e.name }
names.size #=> 3
names.cursor #=> NoMethodError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arr = [], end_cursor = nil, more_results = nil) ⇒ QueryResults

Create a new QueryResults with an array of values.


85
86
87
88
89
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 85

def initialize arr = [], end_cursor = nil, more_results = nil
  super arr
  @end_cursor = end_cursor
  @more_results = more_results
end

Instance Attribute Details

#end_cursorObject (readonly) Also known as: cursor

The end_cursor of the QueryResults.


46
47
48
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 46

def end_cursor
  @end_cursor
end

#more_resultsObject (readonly)

The state of the query after the current batch.

Expected values are:

"MORE_RESULTS_AFTER_LIMIT": "NOT_FINISHED": "NO_MORE_RESULTS":


57
58
59
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 57

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"

Returns:

  • (Boolean)

70
71
72
73
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 70

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"

Returns:

  • (Boolean)

78
79
80
81
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 78

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"

Returns:

  • (Boolean)

62
63
64
65
# File 'lib/gcloud/datastore/dataset/query_results.rb', line 62

def not_finished?
  more_results == Proto.to_more_results_string(
    Proto::QueryResultBatch::MoreResultsType::NOT_FINISHED)
end