query.proto 9.7 KB

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