query.proto 9.6 KB

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