xref: /aosp_15_r20/external/googleapis/google/datastore/v1/datastore.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 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
15syntax = "proto3";
16
17package google.datastore.v1;
18
19import "google/api/annotations.proto";
20import "google/api/client.proto";
21import "google/api/field_behavior.proto";
22import "google/api/routing.proto";
23import "google/datastore/v1/aggregation_result.proto";
24import "google/datastore/v1/entity.proto";
25import "google/datastore/v1/query.proto";
26import "google/datastore/v1/query_profile.proto";
27import "google/protobuf/timestamp.proto";
28
29option csharp_namespace = "Google.Cloud.Datastore.V1";
30option go_package = "google.golang.org/genproto/googleapis/datastore/v1;datastore";
31option java_multiple_files = true;
32option java_outer_classname = "DatastoreProto";
33option java_package = "com.google.datastore.v1";
34option php_namespace = "Google\\Cloud\\Datastore\\V1";
35option ruby_package = "Google::Cloud::Datastore::V1";
36
37// Each RPC normalizes the partition IDs of the keys in its input entities,
38// and always returns entities with keys with normalized partition IDs.
39// This applies to all keys and entities, including those in values, except keys
40// with both an empty path and an empty or unset partition ID. Normalization of
41// input keys sets the project ID (if not already set) to the project ID from
42// the request.
43//
44service Datastore {
45  option (google.api.default_host) = "datastore.googleapis.com";
46  option (google.api.oauth_scopes) =
47      "https://www.googleapis.com/auth/cloud-platform,"
48      "https://www.googleapis.com/auth/datastore";
49
50  // Looks up entities by key.
51  rpc Lookup(LookupRequest) returns (LookupResponse) {
52    option (google.api.http) = {
53      post: "/v1/projects/{project_id}:lookup"
54      body: "*"
55    };
56    option (google.api.routing) = {
57      routing_parameters { field: "project_id" }
58      routing_parameters { field: "database_id" }
59    };
60    option (google.api.method_signature) = "project_id,read_options,keys";
61  }
62
63  // Queries for entities.
64  rpc RunQuery(RunQueryRequest) returns (RunQueryResponse) {
65    option (google.api.http) = {
66      post: "/v1/projects/{project_id}:runQuery"
67      body: "*"
68    };
69    option (google.api.routing) = {
70      routing_parameters { field: "project_id" }
71      routing_parameters { field: "database_id" }
72    };
73  }
74
75  // Runs an aggregation query.
76  rpc RunAggregationQuery(RunAggregationQueryRequest)
77      returns (RunAggregationQueryResponse) {
78    option (google.api.http) = {
79      post: "/v1/projects/{project_id}:runAggregationQuery"
80      body: "*"
81    };
82    option (google.api.routing) = {
83      routing_parameters { field: "project_id" }
84      routing_parameters { field: "database_id" }
85    };
86  }
87
88  // Begins a new transaction.
89  rpc BeginTransaction(BeginTransactionRequest)
90      returns (BeginTransactionResponse) {
91    option (google.api.http) = {
92      post: "/v1/projects/{project_id}:beginTransaction"
93      body: "*"
94    };
95    option (google.api.routing) = {
96      routing_parameters { field: "project_id" }
97      routing_parameters { field: "database_id" }
98    };
99    option (google.api.method_signature) = "project_id";
100  }
101
102  // Commits a transaction, optionally creating, deleting or modifying some
103  // entities.
104  rpc Commit(CommitRequest) returns (CommitResponse) {
105    option (google.api.http) = {
106      post: "/v1/projects/{project_id}:commit"
107      body: "*"
108    };
109    option (google.api.routing) = {
110      routing_parameters { field: "project_id" }
111      routing_parameters { field: "database_id" }
112    };
113    option (google.api.method_signature) =
114        "project_id,mode,transaction,mutations";
115    option (google.api.method_signature) = "project_id,mode,mutations";
116  }
117
118  // Rolls back a transaction.
119  rpc Rollback(RollbackRequest) returns (RollbackResponse) {
120    option (google.api.http) = {
121      post: "/v1/projects/{project_id}:rollback"
122      body: "*"
123    };
124    option (google.api.routing) = {
125      routing_parameters { field: "project_id" }
126      routing_parameters { field: "database_id" }
127    };
128    option (google.api.method_signature) = "project_id,transaction";
129  }
130
131  // Allocates IDs for the given keys, which is useful for referencing an entity
132  // before it is inserted.
133  rpc AllocateIds(AllocateIdsRequest) returns (AllocateIdsResponse) {
134    option (google.api.http) = {
135      post: "/v1/projects/{project_id}:allocateIds"
136      body: "*"
137    };
138    option (google.api.routing) = {
139      routing_parameters { field: "project_id" }
140      routing_parameters { field: "database_id" }
141    };
142    option (google.api.method_signature) = "project_id,keys";
143  }
144
145  // Prevents the supplied keys' IDs from being auto-allocated by Cloud
146  // Datastore.
147  rpc ReserveIds(ReserveIdsRequest) returns (ReserveIdsResponse) {
148    option (google.api.http) = {
149      post: "/v1/projects/{project_id}:reserveIds"
150      body: "*"
151    };
152    option (google.api.routing) = {
153      routing_parameters { field: "project_id" }
154      routing_parameters { field: "database_id" }
155    };
156    option (google.api.method_signature) = "project_id,keys";
157  }
158}
159
160// The request for [Datastore.Lookup][google.datastore.v1.Datastore.Lookup].
161message LookupRequest {
162  // Required. The ID of the project against which to make the request.
163  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
164
165  // The ID of the database against which to make the request.
166  //
167  // '(default)' is not allowed; please use empty string '' to refer the default
168  // database.
169  string database_id = 9;
170
171  // The options for this lookup request.
172  ReadOptions read_options = 1;
173
174  // Required. Keys of entities to look up.
175  repeated Key keys = 3 [(google.api.field_behavior) = REQUIRED];
176}
177
178// The response for [Datastore.Lookup][google.datastore.v1.Datastore.Lookup].
179message LookupResponse {
180  // Entities found as `ResultType.FULL` entities. The order of results in this
181  // field is undefined and has no relation to the order of the keys in the
182  // input.
183  repeated EntityResult found = 1;
184
185  // Entities not found as `ResultType.KEY_ONLY` entities. The order of results
186  // in this field is undefined and has no relation to the order of the keys
187  // in the input.
188  repeated EntityResult missing = 2;
189
190  // A list of keys that were not looked up due to resource constraints. The
191  // order of results in this field is undefined and has no relation to the
192  // order of the keys in the input.
193  repeated Key deferred = 3;
194
195  // The identifier of the transaction that was started as part of this Lookup
196  // request.
197  //
198  // Set only when
199  // [ReadOptions.new_transaction][google.datastore.v1.ReadOptions.new_transaction]
200  // was set in
201  // [LookupRequest.read_options][google.datastore.v1.LookupRequest.read_options].
202  bytes transaction = 5;
203
204  // The time at which these entities were read or found missing.
205  google.protobuf.Timestamp read_time = 7;
206}
207
208// The request for [Datastore.RunQuery][google.datastore.v1.Datastore.RunQuery].
209message RunQueryRequest {
210  // Required. The ID of the project against which to make the request.
211  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
212
213  // The ID of the database against which to make the request.
214  //
215  // '(default)' is not allowed; please use empty string '' to refer the default
216  // database.
217  string database_id = 9;
218
219  // Entities are partitioned into subsets, identified by a partition ID.
220  // Queries are scoped to a single partition.
221  // This partition ID is normalized with the standard default context
222  // partition ID.
223  PartitionId partition_id = 2;
224
225  // The options for this query.
226  ReadOptions read_options = 1;
227
228  // The type of query.
229  oneof query_type {
230    // The query to run.
231    Query query = 3;
232
233    // The GQL query to run. This query must be a non-aggregation query.
234    GqlQuery gql_query = 7;
235  }
236
237  // Optional. Explain options for the query. If set, additional query
238  // statistics will be returned. If not, only query results will be returned.
239  ExplainOptions explain_options = 12 [(google.api.field_behavior) = OPTIONAL];
240}
241
242// The response for
243// [Datastore.RunQuery][google.datastore.v1.Datastore.RunQuery].
244message RunQueryResponse {
245  // A batch of query results (always present).
246  QueryResultBatch batch = 1;
247
248  // The parsed form of the `GqlQuery` from the request, if it was set.
249  Query query = 2;
250
251  // The identifier of the transaction that was started as part of this
252  // RunQuery request.
253  //
254  // Set only when
255  // [ReadOptions.new_transaction][google.datastore.v1.ReadOptions.new_transaction]
256  // was set in
257  // [RunQueryRequest.read_options][google.datastore.v1.RunQueryRequest.read_options].
258  bytes transaction = 5;
259
260  // Query explain metrics. This is only present when the
261  // [RunQueryRequest.explain_options][google.datastore.v1.RunQueryRequest.explain_options]
262  // is provided, and it is sent only once with the last response in the stream.
263  ExplainMetrics explain_metrics = 9;
264}
265
266// The request for
267// [Datastore.RunAggregationQuery][google.datastore.v1.Datastore.RunAggregationQuery].
268message RunAggregationQueryRequest {
269  // Required. The ID of the project against which to make the request.
270  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
271
272  // The ID of the database against which to make the request.
273  //
274  // '(default)' is not allowed; please use empty string '' to refer the default
275  // database.
276  string database_id = 9;
277
278  // Entities are partitioned into subsets, identified by a partition ID.
279  // Queries are scoped to a single partition.
280  // This partition ID is normalized with the standard default context
281  // partition ID.
282  PartitionId partition_id = 2;
283
284  // The options for this query.
285  ReadOptions read_options = 1;
286
287  // The type of query.
288  oneof query_type {
289    // The query to run.
290    AggregationQuery aggregation_query = 3;
291
292    // The GQL query to run. This query must be an aggregation query.
293    GqlQuery gql_query = 7;
294  }
295
296  // Optional. Explain options for the query. If set, additional query
297  // statistics will be returned. If not, only query results will be returned.
298  ExplainOptions explain_options = 11 [(google.api.field_behavior) = OPTIONAL];
299}
300
301// The response for
302// [Datastore.RunAggregationQuery][google.datastore.v1.Datastore.RunAggregationQuery].
303message RunAggregationQueryResponse {
304  // A batch of aggregation results. Always present.
305  AggregationResultBatch batch = 1;
306
307  // The parsed form of the `GqlQuery` from the request, if it was set.
308  AggregationQuery query = 2;
309
310  // The identifier of the transaction that was started as part of this
311  // RunAggregationQuery request.
312  //
313  // Set only when
314  // [ReadOptions.new_transaction][google.datastore.v1.ReadOptions.new_transaction]
315  // was set in
316  // [RunAggregationQueryRequest.read_options][google.datastore.v1.RunAggregationQueryRequest.read_options].
317  bytes transaction = 5;
318
319  // Query explain metrics. This is only present when the
320  // [RunAggregationQueryRequest.explain_options][google.datastore.v1.RunAggregationQueryRequest.explain_options]
321  // is provided, and it is sent only once with the last response in the stream.
322  ExplainMetrics explain_metrics = 9;
323}
324
325// The request for
326// [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
327message BeginTransactionRequest {
328  // Required. The ID of the project against which to make the request.
329  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
330
331  // The ID of the database against which to make the request.
332  //
333  // '(default)' is not allowed; please use empty string '' to refer the default
334  // database.
335  string database_id = 9;
336
337  // Options for a new transaction.
338  TransactionOptions transaction_options = 10;
339}
340
341// The response for
342// [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
343message BeginTransactionResponse {
344  // The transaction identifier (always present).
345  bytes transaction = 1;
346}
347
348// The request for [Datastore.Rollback][google.datastore.v1.Datastore.Rollback].
349message RollbackRequest {
350  // Required. The ID of the project against which to make the request.
351  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
352
353  // The ID of the database against which to make the request.
354  //
355  // '(default)' is not allowed; please use empty string '' to refer the default
356  // database.
357  string database_id = 9;
358
359  // Required. The transaction identifier, returned by a call to
360  // [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
361  bytes transaction = 1 [(google.api.field_behavior) = REQUIRED];
362}
363
364// The response for
365// [Datastore.Rollback][google.datastore.v1.Datastore.Rollback]. (an empty
366// message).
367message RollbackResponse {}
368
369// The request for [Datastore.Commit][google.datastore.v1.Datastore.Commit].
370message CommitRequest {
371  // The modes available for commits.
372  enum Mode {
373    // Unspecified. This value must not be used.
374    MODE_UNSPECIFIED = 0;
375
376    // Transactional: The mutations are either all applied, or none are applied.
377    // Learn about transactions
378    // [here](https://cloud.google.com/datastore/docs/concepts/transactions).
379    TRANSACTIONAL = 1;
380
381    // Non-transactional: The mutations may not apply as all or none.
382    NON_TRANSACTIONAL = 2;
383  }
384
385  // Required. The ID of the project against which to make the request.
386  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
387
388  // The ID of the database against which to make the request.
389  //
390  // '(default)' is not allowed; please use empty string '' to refer the default
391  // database.
392  string database_id = 9;
393
394  // The type of commit to perform. Defaults to `TRANSACTIONAL`.
395  Mode mode = 5;
396
397  // Must be set when mode is `TRANSACTIONAL`.
398  oneof transaction_selector {
399    // The identifier of the transaction associated with the commit. A
400    // transaction identifier is returned by a call to
401    // [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
402    bytes transaction = 1;
403
404    // Options for beginning a new transaction for this request.
405    // The transaction is committed when the request completes. If specified,
406    // [TransactionOptions.mode][google.datastore.v1.TransactionOptions] must be
407    // [TransactionOptions.ReadWrite][google.datastore.v1.TransactionOptions.ReadWrite].
408    TransactionOptions single_use_transaction = 10;
409  }
410
411  // The mutations to perform.
412  //
413  // When mode is `TRANSACTIONAL`, mutations affecting a single entity are
414  // applied in order. The following sequences of mutations affecting a single
415  // entity are not permitted in a single `Commit` request:
416  //
417  // - `insert` followed by `insert`
418  // - `update` followed by `insert`
419  // - `upsert` followed by `insert`
420  // - `delete` followed by `update`
421  //
422  // When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single
423  // entity.
424  repeated Mutation mutations = 6;
425}
426
427// The response for [Datastore.Commit][google.datastore.v1.Datastore.Commit].
428message CommitResponse {
429  // The result of performing the mutations.
430  // The i-th mutation result corresponds to the i-th mutation in the request.
431  repeated MutationResult mutation_results = 3;
432
433  // The number of index entries updated during the commit, or zero if none were
434  // updated.
435  int32 index_updates = 4;
436
437  // The transaction commit timestamp. Not set for non-transactional commits.
438  google.protobuf.Timestamp commit_time = 8;
439}
440
441// The request for
442// [Datastore.AllocateIds][google.datastore.v1.Datastore.AllocateIds].
443message AllocateIdsRequest {
444  // Required. The ID of the project against which to make the request.
445  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
446
447  // The ID of the database against which to make the request.
448  //
449  // '(default)' is not allowed; please use empty string '' to refer the default
450  // database.
451  string database_id = 9;
452
453  // Required. A list of keys with incomplete key paths for which to allocate
454  // IDs. No key may be reserved/read-only.
455  repeated Key keys = 1 [(google.api.field_behavior) = REQUIRED];
456}
457
458// The response for
459// [Datastore.AllocateIds][google.datastore.v1.Datastore.AllocateIds].
460message AllocateIdsResponse {
461  // The keys specified in the request (in the same order), each with
462  // its key path completed with a newly allocated ID.
463  repeated Key keys = 1;
464}
465
466// The request for
467// [Datastore.ReserveIds][google.datastore.v1.Datastore.ReserveIds].
468message ReserveIdsRequest {
469  // Required. The ID of the project against which to make the request.
470  string project_id = 8 [(google.api.field_behavior) = REQUIRED];
471
472  // The ID of the database against which to make the request.
473  //
474  // '(default)' is not allowed; please use empty string '' to refer the default
475  // database.
476  string database_id = 9;
477
478  // Required. A list of keys with complete key paths whose numeric IDs should
479  // not be auto-allocated.
480  repeated Key keys = 1 [(google.api.field_behavior) = REQUIRED];
481}
482
483// The response for
484// [Datastore.ReserveIds][google.datastore.v1.Datastore.ReserveIds].
485message ReserveIdsResponse {}
486
487// A mutation to apply to an entity.
488message Mutation {
489  // The mutation operation.
490  //
491  // For `insert`, `update`, and `upsert`:
492  // - The entity's key must not be reserved/read-only.
493  // - No property in the entity may have a reserved name,
494  //   not even a property in an entity in a value.
495  // - No value in the entity may have meaning 18,
496  //   not even a value in an entity in another value.
497  oneof operation {
498    // The entity to insert. The entity must not already exist.
499    // The entity key's final path element may be incomplete.
500    Entity insert = 4;
501
502    // The entity to update. The entity must already exist.
503    // Must have a complete key path.
504    Entity update = 5;
505
506    // The entity to upsert. The entity may or may not already exist.
507    // The entity key's final path element may be incomplete.
508    Entity upsert = 6;
509
510    // The key of the entity to delete. The entity may or may not already exist.
511    // Must have a complete key path and must not be reserved/read-only.
512    Key delete = 7;
513  }
514
515  // When set, the server will detect whether or not this mutation conflicts
516  // with the current version of the entity on the server. Conflicting mutations
517  // are not applied, and are marked as such in MutationResult.
518  oneof conflict_detection_strategy {
519    // The version of the entity that this mutation is being applied
520    // to. If this does not match the current version on the server, the
521    // mutation conflicts.
522    int64 base_version = 8;
523
524    // The update time of the entity that this mutation is being applied
525    // to. If this does not match the current update time on the server, the
526    // mutation conflicts.
527    google.protobuf.Timestamp update_time = 11;
528  }
529}
530
531// The result of applying a mutation.
532message MutationResult {
533  // The automatically allocated key.
534  // Set only when the mutation allocated a key.
535  Key key = 3;
536
537  // The version of the entity on the server after processing the mutation. If
538  // the mutation doesn't change anything on the server, then the version will
539  // be the version of the current entity or, if no entity is present, a version
540  // that is strictly greater than the version of any previous entity and less
541  // than the version of any possible future entity.
542  int64 version = 4;
543
544  // The create time of the entity. This field will not be set after a 'delete'.
545  google.protobuf.Timestamp create_time = 7;
546
547  // The update time of the entity on the server after processing the mutation.
548  // If the mutation doesn't change anything on the server, then the timestamp
549  // will be the update timestamp of the current entity. This field will not be
550  // set after a 'delete'.
551  google.protobuf.Timestamp update_time = 6;
552
553  // Whether a conflict was detected for this mutation. Always false when a
554  // conflict detection strategy field is not set in the mutation.
555  bool conflict_detected = 5;
556}
557
558// The options shared by read requests.
559message ReadOptions {
560  // The possible values for read consistencies.
561  enum ReadConsistency {
562    // Unspecified. This value must not be used.
563    READ_CONSISTENCY_UNSPECIFIED = 0;
564
565    // Strong consistency.
566    STRONG = 1;
567
568    // Eventual consistency.
569    EVENTUAL = 2;
570  }
571
572  // For Cloud Datastore, if read_consistency is not specified, then lookups and
573  // ancestor queries default to `read_consistency`=`STRONG`, global queries
574  // default to `read_consistency`=`EVENTUAL`.
575  //
576  // For Cloud Firestore in Datastore mode, if read_consistency is not specified
577  // then lookups and all queries default to `read_consistency`=`STRONG`.
578  //
579  // Explicitly setting `read_consistency`=`EVENTUAL` will result in eventually
580  // consistent lookups & queries in both Cloud Datastore & Cloud Firestore in
581  // Datastore mode.
582  oneof consistency_type {
583    // The non-transactional read consistency to use.
584    ReadConsistency read_consistency = 1;
585
586    // The identifier of the transaction in which to read. A
587    // transaction identifier is returned by a call to
588    // [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction].
589    bytes transaction = 2;
590
591    // Options for beginning a new transaction for this request.
592    //
593    // The new transaction identifier will be returned in the corresponding
594    // response as either
595    // [LookupResponse.transaction][google.datastore.v1.LookupResponse.transaction]
596    // or
597    // [RunQueryResponse.transaction][google.datastore.v1.RunQueryResponse.transaction].
598    TransactionOptions new_transaction = 3;
599
600    // Reads entities as they were at the given time. This value is only
601    // supported for Cloud Firestore in Datastore mode.
602    //
603    // This must be a microsecond precision timestamp within the past one hour,
604    // or if Point-in-Time Recovery is enabled, can additionally be a whole
605    // minute timestamp within the past 7 days.
606    google.protobuf.Timestamp read_time = 4;
607  }
608}
609
610// Options for beginning a new transaction.
611//
612// Transactions can be created explicitly with calls to
613// [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]
614// or implicitly by setting
615// [ReadOptions.new_transaction][google.datastore.v1.ReadOptions.new_transaction]
616// in read requests.
617message TransactionOptions {
618  // Options specific to read / write transactions.
619  message ReadWrite {
620    // The transaction identifier of the transaction being retried.
621    bytes previous_transaction = 1;
622  }
623
624  // Options specific to read-only transactions.
625  message ReadOnly {
626    // Reads entities at the given time.
627    //
628    // This must be a microsecond precision timestamp within the past one hour,
629    // or if Point-in-Time Recovery is enabled, can additionally be a whole
630    // minute timestamp within the past 7 days.
631    google.protobuf.Timestamp read_time = 1;
632  }
633
634  // The `mode` of the transaction, indicating whether write operations are
635  // supported.
636  oneof mode {
637    // The transaction should allow both reads and writes.
638    ReadWrite read_write = 1;
639
640    // The transaction should only allow reads.
641    ReadOnly read_only = 2;
642  }
643}
644