xref: /aosp_15_r20/external/googleapis/google/datastore/v1beta3/query.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2018 Google Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.datastore.v1beta3;
18
19import "google/api/annotations.proto";
20import "google/datastore/v1beta3/entity.proto";
21import "google/protobuf/wrappers.proto";
22import "google/type/latlng.proto";
23
24option csharp_namespace = "Google.Cloud.Datastore.V1Beta3";
25option go_package = "google.golang.org/genproto/googleapis/datastore/v1beta3;datastore";
26option java_multiple_files = true;
27option java_outer_classname = "QueryProto";
28option java_package = "com.google.datastore.v1beta3";
29option php_namespace = "Google\\Cloud\\Datastore\\V1beta3";
30option ruby_package = "Google::Cloud::Datastore::V1beta3";
31
32// The result of fetching an entity from Datastore.
33message EntityResult {
34  // Specifies what data the 'entity' field contains.
35  // A `ResultType` is either implied (for example, in `LookupResponse.missing`
36  // from `datastore.proto`, it is always `KEY_ONLY`) or specified by context
37  // (for example, in message `QueryResultBatch`, field `entity_result_type`
38  // specifies a `ResultType` for all the values in field `entity_results`).
39  enum ResultType {
40    // Unspecified. This value is never used.
41    RESULT_TYPE_UNSPECIFIED = 0;
42
43    // The key and properties.
44    FULL = 1;
45
46    // A projected subset of properties. The entity may have no key.
47    PROJECTION = 2;
48
49    // Only the key.
50    KEY_ONLY = 3;
51  }
52
53  // The resulting entity.
54  Entity entity = 1;
55
56  // The version of the entity, a strictly positive number that monotonically
57  // increases with changes to the entity.
58  //
59  // This field is set for
60  // [`FULL`][google.datastore.v1beta3.EntityResult.ResultType.FULL] entity
61  // results.
62  //
63  // For [missing][google.datastore.v1beta3.LookupResponse.missing] entities in
64  // `LookupResponse`, this is the version of the snapshot that was used to look
65  // up the entity, and it is always set except for eventually consistent reads.
66  int64 version = 4;
67
68  // A cursor that points to the position after the result entity.
69  // Set only when the `EntityResult` is part of a `QueryResultBatch` message.
70  bytes cursor = 3;
71}
72
73// A query for entities.
74message Query {
75  // The projection to return. Defaults to returning all properties.
76  repeated Projection projection = 2;
77
78  // The kinds to query (if empty, returns entities of all kinds).
79  // Currently at most 1 kind may be specified.
80  repeated KindExpression kind = 3;
81
82  // The filter to apply.
83  Filter filter = 4;
84
85  // The order to apply to the query results (if empty, order is unspecified).
86  repeated PropertyOrder order = 5;
87
88  // The properties to make distinct. The query results will contain the first
89  // result for each distinct combination of values for the given properties
90  // (if empty, all results are returned).
91  repeated PropertyReference distinct_on = 6;
92
93  // A starting point for the query results. Query cursors are
94  // returned in query result batches and
95  // [can only be used to continue the same
96  // query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
97  bytes start_cursor = 7;
98
99  // An ending point for the query results. Query cursors are
100  // returned in query result batches and
101  // [can only be used to limit the same
102  // query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
103  bytes end_cursor = 8;
104
105  // The number of results to skip. Applies before limit, but after all other
106  // constraints. Optional. Must be >= 0 if specified.
107  int32 offset = 10;
108
109  // The maximum number of results to return. Applies after all other
110  // constraints. Optional.
111  // Unspecified is interpreted as no limit.
112  // Must be >= 0 if specified.
113  google.protobuf.Int32Value limit = 12;
114}
115
116// A representation of a kind.
117message KindExpression {
118  // The name of the kind.
119  string name = 1;
120}
121
122// A reference to a property relative to the kind expressions.
123message PropertyReference {
124  // The name of the property.
125  // If name includes "."s, it may be interpreted as a property name path.
126  string name = 2;
127}
128
129// A representation of a property in a projection.
130message Projection {
131  // The property to project.
132  PropertyReference property = 1;
133}
134
135// The desired order for a specific property.
136message PropertyOrder {
137  // The sort direction.
138  enum Direction {
139    // Unspecified. This value must not be used.
140    DIRECTION_UNSPECIFIED = 0;
141
142    // Ascending.
143    ASCENDING = 1;
144
145    // Descending.
146    DESCENDING = 2;
147  }
148
149  // The property to order by.
150  PropertyReference property = 1;
151
152  // The direction to order by. Defaults to `ASCENDING`.
153  Direction direction = 2;
154}
155
156// A holder for any type of filter.
157message Filter {
158  // The type of filter.
159  oneof filter_type {
160    // A composite filter.
161    CompositeFilter composite_filter = 1;
162
163    // A filter on a property.
164    PropertyFilter property_filter = 2;
165  }
166}
167
168// A filter that merges multiple other filters using the given operator.
169message CompositeFilter {
170  // A composite filter operator.
171  enum Operator {
172    // Unspecified. This value must not be used.
173    OPERATOR_UNSPECIFIED = 0;
174
175    // The results are required to satisfy each of the combined filters.
176    AND = 1;
177  }
178
179  // The operator for combining multiple filters.
180  Operator op = 1;
181
182  // The list of filters to combine.
183  // Must contain at least one filter.
184  repeated Filter filters = 2;
185}
186
187// A filter on a specific property.
188message PropertyFilter {
189  // A property filter operator.
190  enum Operator {
191    // Unspecified. This value must not be used.
192    OPERATOR_UNSPECIFIED = 0;
193
194    // Less than.
195    LESS_THAN = 1;
196
197    // Less than or equal.
198    LESS_THAN_OR_EQUAL = 2;
199
200    // Greater than.
201    GREATER_THAN = 3;
202
203    // Greater than or equal.
204    GREATER_THAN_OR_EQUAL = 4;
205
206    // Equal.
207    EQUAL = 5;
208
209    // Has ancestor.
210    HAS_ANCESTOR = 11;
211  }
212
213  // The property to filter by.
214  PropertyReference property = 1;
215
216  // The operator to filter by.
217  Operator op = 2;
218
219  // The value to compare the property to.
220  Value value = 3;
221}
222
223// A [GQL
224// query](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
225message GqlQuery {
226  // A string of the format described
227  // [here](https://cloud.google.com/datastore/docs/apis/gql/gql_reference).
228  string query_string = 1;
229
230  // When false, the query string must not contain any literals and instead must
231  // bind all values. For example,
232  // `SELECT * FROM Kind WHERE a = 'string literal'` is not allowed, while
233  // `SELECT * FROM Kind WHERE a = @value` is.
234  bool allow_literals = 2;
235
236  // For each non-reserved named binding site in the query string, there must be
237  // a named parameter with that name, but not necessarily the inverse.
238  //
239  // Key must match regex `[A-Za-z_$][A-Za-z_$0-9]*`, must not match regex
240  // `__.*__`, and must not be `""`.
241  map<string, GqlQueryParameter> named_bindings = 5;
242
243  // Numbered binding site @1 references the first numbered parameter,
244  // effectively using 1-based indexing, rather than the usual 0.
245  //
246  // For each binding site numbered i in `query_string`, there must be an i-th
247  // numbered parameter. The inverse must also be true.
248  repeated GqlQueryParameter positional_bindings = 4;
249}
250
251// A binding parameter for a GQL query.
252message GqlQueryParameter {
253  // The type of parameter.
254  oneof parameter_type {
255    // A value parameter.
256    Value value = 2;
257
258    // A query cursor. Query cursors are returned in query
259    // result batches.
260    bytes cursor = 3;
261  }
262}
263
264// A batch of results produced by a query.
265message QueryResultBatch {
266  // The possible values for the `more_results` field.
267  enum MoreResultsType {
268    // Unspecified. This value is never used.
269    MORE_RESULTS_TYPE_UNSPECIFIED = 0;
270
271    // There may be additional batches to fetch from this query.
272    NOT_FINISHED = 1;
273
274    // The query is finished, but there may be more results after the limit.
275    MORE_RESULTS_AFTER_LIMIT = 2;
276
277    // The query is finished, but there may be more results after the end
278    // cursor.
279    MORE_RESULTS_AFTER_CURSOR = 4;
280
281    // The query is finished, and there are no more results.
282    NO_MORE_RESULTS = 3;
283  }
284
285  // The number of results skipped, typically because of an offset.
286  int32 skipped_results = 6;
287
288  // A cursor that points to the position after the last skipped result.
289  // Will be set when `skipped_results` != 0.
290  bytes skipped_cursor = 3;
291
292  // The result type for every entity in `entity_results`.
293  EntityResult.ResultType entity_result_type = 1;
294
295  // The results for this batch.
296  repeated EntityResult entity_results = 2;
297
298  // A cursor that points to the position after the last result in the batch.
299  bytes end_cursor = 4;
300
301  // The state of the query after the current batch.
302  MoreResultsType more_results = 5;
303
304  // The version number of the snapshot this batch was returned from.
305  // This applies to the range of results from the query's `start_cursor` (or
306  // the beginning of the query if no cursor was given) to this batch's
307  // `end_cursor` (not the query's `end_cursor`).
308  //
309  // In a single transaction, subsequent query result batches for the same query
310  // can have a greater snapshot version number. Each batch's snapshot version
311  // is valid for all preceding batches.
312  // The value will be zero for eventually consistent queries.
313  int64 snapshot_version = 7;
314}
315