query.proto 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Copyright 2021 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.firestore.v1;
  16. import "google/firestore/v1/document.proto";
  17. import "google/protobuf/wrappers.proto";
  18. import "google/api/annotations.proto";
  19. option csharp_namespace = "Google.Cloud.Firestore.V1";
  20. option go_package = "google.golang.org/genproto/googleapis/firestore/v1;firestore";
  21. option java_multiple_files = true;
  22. option java_outer_classname = "QueryProto";
  23. option java_package = "com.google.firestore.v1";
  24. option objc_class_prefix = "GCFS";
  25. option php_namespace = "Google\\Cloud\\Firestore\\V1";
  26. option ruby_package = "Google::Cloud::Firestore::V1";
  27. // A Firestore query.
  28. message StructuredQuery {
  29. // A selection of a collection, such as `messages as m1`.
  30. message CollectionSelector {
  31. // The collection ID.
  32. // When set, selects only collections with this ID.
  33. string collection_id = 2;
  34. // When false, selects only collections that are immediate children of
  35. // the `parent` specified in the containing `RunQueryRequest`.
  36. // When true, selects all descendant collections.
  37. bool all_descendants = 3;
  38. }
  39. // A filter.
  40. message Filter {
  41. // The type of filter.
  42. oneof filter_type {
  43. // A composite filter.
  44. CompositeFilter composite_filter = 1;
  45. // A filter on a document field.
  46. FieldFilter field_filter = 2;
  47. // A filter that takes exactly one argument.
  48. UnaryFilter unary_filter = 3;
  49. }
  50. }
  51. // A filter that merges multiple other filters using the given operator.
  52. message CompositeFilter {
  53. // A composite filter operator.
  54. enum Operator {
  55. // Unspecified. This value must not be used.
  56. OPERATOR_UNSPECIFIED = 0;
  57. // The results are required to satisfy each of the combined filters.
  58. AND = 1;
  59. }
  60. // The operator for combining multiple filters.
  61. Operator op = 1;
  62. // The list of filters to combine.
  63. // Must contain at least one filter.
  64. repeated Filter filters = 2;
  65. }
  66. // A filter on a specific field.
  67. message FieldFilter {
  68. // A field filter operator.
  69. enum Operator {
  70. // Unspecified. This value must not be used.
  71. OPERATOR_UNSPECIFIED = 0;
  72. // The given `field` is less than the given `value`.
  73. //
  74. // Requires:
  75. //
  76. // * That `field` come first in `order_by`.
  77. LESS_THAN = 1;
  78. // The given `field` is less than or equal to the given `value`.
  79. //
  80. // Requires:
  81. //
  82. // * That `field` come first in `order_by`.
  83. LESS_THAN_OR_EQUAL = 2;
  84. // The given `field` is greater than the given `value`.
  85. //
  86. // Requires:
  87. //
  88. // * That `field` come first in `order_by`.
  89. GREATER_THAN = 3;
  90. // The given `field` is greater than or equal to the given `value`.
  91. //
  92. // Requires:
  93. //
  94. // * That `field` come first in `order_by`.
  95. GREATER_THAN_OR_EQUAL = 4;
  96. // The given `field` is equal to the given `value`.
  97. EQUAL = 5;
  98. // The given `field` is not equal to the given `value`.
  99. //
  100. // Requires:
  101. //
  102. // * No other `NOT_EQUAL`, `NOT_IN`, `IS_NOT_NULL`, or `IS_NOT_NAN`.
  103. // * That `field` comes first in the `order_by`.
  104. NOT_EQUAL = 6;
  105. // The given `field` is an array that contains the given `value`.
  106. ARRAY_CONTAINS = 7;
  107. // The given `field` is equal to at least one value in the given array.
  108. //
  109. // Requires:
  110. //
  111. // * That `value` is a non-empty `ArrayValue` with at most 10 values.
  112. // * No other `IN` or `ARRAY_CONTAINS_ANY` or `NOT_IN`.
  113. IN = 8;
  114. // The given `field` is an array that contains any of the values in the
  115. // given array.
  116. //
  117. // Requires:
  118. //
  119. // * That `value` is a non-empty `ArrayValue` with at most 10 values.
  120. // * No other `IN` or `ARRAY_CONTAINS_ANY` or `NOT_IN`.
  121. ARRAY_CONTAINS_ANY = 9;
  122. // The value of the `field` is not in the given array.
  123. //
  124. // Requires:
  125. //
  126. // * That `value` is a non-empty `ArrayValue` with at most 10 values.
  127. // * No other `IN`, `ARRAY_CONTAINS_ANY`, `NOT_IN`, `NOT_EQUAL`,
  128. // `IS_NOT_NULL`, or `IS_NOT_NAN`.
  129. // * That `field` comes first in the `order_by`.
  130. NOT_IN = 10;
  131. }
  132. // The field to filter by.
  133. FieldReference field = 1;
  134. // The operator to filter by.
  135. Operator op = 2;
  136. // The value to compare to.
  137. Value value = 3;
  138. }
  139. // A filter with a single operand.
  140. message UnaryFilter {
  141. // A unary operator.
  142. enum Operator {
  143. // Unspecified. This value must not be used.
  144. OPERATOR_UNSPECIFIED = 0;
  145. // The given `field` is equal to `NaN`.
  146. IS_NAN = 2;
  147. // The given `field` is equal to `NULL`.
  148. IS_NULL = 3;
  149. // The given `field` is not equal to `NaN`.
  150. //
  151. // Requires:
  152. //
  153. // * No other `NOT_EQUAL`, `NOT_IN`, `IS_NOT_NULL`, or `IS_NOT_NAN`.
  154. // * That `field` comes first in the `order_by`.
  155. IS_NOT_NAN = 4;
  156. // The given `field` is not equal to `NULL`.
  157. //
  158. // Requires:
  159. //
  160. // * A single `NOT_EQUAL`, `NOT_IN`, `IS_NOT_NULL`, or `IS_NOT_NAN`.
  161. // * That `field` comes first in the `order_by`.
  162. IS_NOT_NULL = 5;
  163. }
  164. // The unary operator to apply.
  165. Operator op = 1;
  166. // The argument to the filter.
  167. oneof operand_type {
  168. // The field to which to apply the operator.
  169. FieldReference field = 2;
  170. }
  171. }
  172. // An order on a field.
  173. message Order {
  174. // The field to order by.
  175. FieldReference field = 1;
  176. // The direction to order by. Defaults to `ASCENDING`.
  177. Direction direction = 2;
  178. }
  179. // A reference to a field, such as `max(messages.time) as max_time`.
  180. message FieldReference {
  181. string field_path = 2;
  182. }
  183. // The projection of document's fields to return.
  184. message Projection {
  185. // The fields to return.
  186. //
  187. // If empty, all fields are returned. To only return the name
  188. // of the document, use `['__name__']`.
  189. repeated FieldReference fields = 2;
  190. }
  191. // A sort direction.
  192. enum Direction {
  193. // Unspecified.
  194. DIRECTION_UNSPECIFIED = 0;
  195. // Ascending.
  196. ASCENDING = 1;
  197. // Descending.
  198. DESCENDING = 2;
  199. }
  200. // The projection to return.
  201. Projection select = 1;
  202. // The collections to query.
  203. repeated CollectionSelector from = 2;
  204. // The filter to apply.
  205. Filter where = 3;
  206. // The order to apply to the query results.
  207. //
  208. // Firestore guarantees a stable ordering through the following rules:
  209. //
  210. // * Any field required to appear in `order_by`, that is not already
  211. // specified in `order_by`, is appended to the order in field name order
  212. // by default.
  213. // * If an order on `__name__` is not specified, it is appended by default.
  214. //
  215. // Fields are appended with the same sort direction as the last order
  216. // specified, or 'ASCENDING' if no order was specified. For example:
  217. //
  218. // * `SELECT * FROM Foo ORDER BY A` becomes
  219. // `SELECT * FROM Foo ORDER BY A, __name__`
  220. // * `SELECT * FROM Foo ORDER BY A DESC` becomes
  221. // `SELECT * FROM Foo ORDER BY A DESC, __name__ DESC`
  222. // * `SELECT * FROM Foo WHERE A > 1` becomes
  223. // `SELECT * FROM Foo WHERE A > 1 ORDER BY A, __name__`
  224. repeated Order order_by = 4;
  225. // A starting point for the query results.
  226. Cursor start_at = 7;
  227. // A end point for the query results.
  228. Cursor end_at = 8;
  229. // The number of results to skip.
  230. //
  231. // Applies before limit, but after all other constraints. Must be >= 0 if
  232. // specified.
  233. int32 offset = 6;
  234. // The maximum number of results to return.
  235. //
  236. // Applies after all other constraints.
  237. // Must be >= 0 if specified.
  238. google.protobuf.Int32Value limit = 5;
  239. }
  240. // A position in a query result set.
  241. message Cursor {
  242. // The values that represent a position, in the order they appear in
  243. // the order by clause of a query.
  244. //
  245. // Can contain fewer values than specified in the order by clause.
  246. repeated Value values = 1;
  247. // If the position is just before or just after the given values, relative
  248. // to the sort order defined by the query.
  249. bool before = 2;
  250. }