Class: Gcloud::Datastore::Query
- Inherits:
-
Object
- Object
- Gcloud::Datastore::Query
- Defined in:
- lib/gcloud/datastore/query.rb
Overview
Instance Method Summary collapse
-
#ancestor(parent) ⇒ Object
Add a filter for entities that inherit from a key.
-
#group_by(*names) ⇒ Object
Group results by a list of properties.
-
#initialize ⇒ Query
constructor
Returns a new query object.
-
#kind(*kinds) ⇒ Object
Add the kind of entities to query.
-
#limit(num) ⇒ Object
Set a limit on the number of results to be returned.
-
#offset(num) ⇒ Object
Set an offset for the results to be returned.
-
#order(name, direction = :asc) ⇒ Object
Sort the results by a property name.
-
#select(*names) ⇒ Object
(also: #projection)
Retrieve only select properties from the matched entities.
-
#start(cursor) ⇒ Object
(also: #cursor)
Set the cursor to start the results at.
-
#to_proto ⇒ Object
rubocop:disable Style/TrivialAccessors.
-
#where(name, operator, value) ⇒ Object
(also: #filter)
Add a property filter to the query.
Constructor Details
Instance Method Details
#ancestor(parent) ⇒ Object
83 84 85 86 87 |
# File 'lib/gcloud/datastore/query.rb', line 83 def ancestor parent # Use key if given an entity parent = parent.key if parent.respond_to? :key where "__key__", "~", parent end |
#group_by(*names) ⇒ Object
175 176 177 178 179 |
# File 'lib/gcloud/datastore/query.rb', line 175 def group_by *names @_query.group_by ||= [] @_query.group_by += Proto.new_property_references(*names) self end |
#kind(*kinds) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/gcloud/datastore/query.rb', line 45 def kind *kinds @_query.kind ||= Proto::KindExpression.new @_query.kind.name ||= [] @_query.kind.name |= kinds self end |
#limit(num) ⇒ Object
118 119 120 121 |
# File 'lib/gcloud/datastore/query.rb', line 118 def limit num @_query.limit = num self end |
#offset(num) ⇒ Object
132 133 134 135 |
# File 'lib/gcloud/datastore/query.rb', line 132 def offset num @_query.offset = num self end |
#order(name, direction = :asc) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/gcloud/datastore/query.rb', line 100 def order name, direction = :asc @_query.order ||= [] po = Proto::PropertyOrder.new po.property = Proto::PropertyReference.new po.property.name = name po.direction = Proto.to_prop_order_direction direction @_query.order << po self end |
#select(*names) ⇒ Object Also known as: projection
160 161 162 163 164 |
# File 'lib/gcloud/datastore/query.rb', line 160 def select *names @_query.projection ||= [] @_query.projection += Proto.new_property_expressions(*names) self end |
#start(cursor) ⇒ Object Also known as: cursor
146 147 148 149 |
# File 'lib/gcloud/datastore/query.rb', line 146 def start cursor @_query.start_cursor = Proto.decode_cursor cursor self end |
#to_proto ⇒ Object
rubocop:disable Style/TrivialAccessors
182 183 184 185 |
# File 'lib/gcloud/datastore/query.rb', line 182 def to_proto #:nodoc: # Disabled rubocop because this implementation will most likely change. @_query end |
#where(name, operator, value) ⇒ Object Also known as: filter
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gcloud/datastore/query.rb', line 60 def where name, operator, value # Initialize filter @_query.filter ||= Proto.new_filter.tap do |f| f.composite_filter = Proto.new_composite_filter end # Create new property filter filter = Proto.new_filter.tap do |f| f.property_filter = Proto.new_property_filter name, operator, value end # Add new property filter to the list @_query.filter.composite_filter.filter << filter self end |