xref: /aosp_15_r20/external/googleapis/google/datastore/v1beta3/datastore.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/datastore/v1beta3/query.proto";
22
23option csharp_namespace = "Google.Cloud.Datastore.V1Beta3";
24option go_package = "google.golang.org/genproto/googleapis/datastore/v1beta3;datastore";
25option java_multiple_files = true;
26option java_outer_classname = "DatastoreProto";
27option java_package = "com.google.datastore.v1beta3";
28option php_namespace = "Google\\Cloud\\Datastore\\V1beta3";
29option ruby_package = "Google::Cloud::Datastore::V1beta3";
30
31// Each RPC normalizes the partition IDs of the keys in its input entities,
32// and always returns entities with keys with normalized partition IDs.
33// This applies to all keys and entities, including those in values, except keys
34// with both an empty path and an empty or unset partition ID. Normalization of
35// input keys sets the project ID (if not already set) to the project ID from
36// the request.
37//
38service Datastore {
39  // Looks up entities by key.
40  rpc Lookup(LookupRequest) returns (LookupResponse) {
41    option (google.api.http) = {
42      post: "/v1beta3/projects/{project_id}:lookup"
43      body: "*"
44    };
45  }
46
47  // Queries for entities.
48  rpc RunQuery(RunQueryRequest) returns (RunQueryResponse) {
49    option (google.api.http) = {
50      post: "/v1beta3/projects/{project_id}:runQuery"
51      body: "*"
52    };
53  }
54
55  // Begins a new transaction.
56  rpc BeginTransaction(BeginTransactionRequest)
57      returns (BeginTransactionResponse) {
58    option (google.api.http) = {
59      post: "/v1beta3/projects/{project_id}:beginTransaction"
60      body: "*"
61    };
62  }
63
64  // Commits a transaction, optionally creating, deleting or modifying some
65  // entities.
66  rpc Commit(CommitRequest) returns (CommitResponse) {
67    option (google.api.http) = {
68      post: "/v1beta3/projects/{project_id}:commit"
69      body: "*"
70    };
71  }
72
73  // Rolls back a transaction.
74  rpc Rollback(RollbackRequest) returns (RollbackResponse) {
75    option (google.api.http) = {
76      post: "/v1beta3/projects/{project_id}:rollback"
77      body: "*"
78    };
79  }
80
81  // Allocates IDs for the given keys, which is useful for referencing an entity
82  // before it is inserted.
83  rpc AllocateIds(AllocateIdsRequest) returns (AllocateIdsResponse) {
84    option (google.api.http) = {
85      post: "/v1beta3/projects/{project_id}:allocateIds"
86      body: "*"
87    };
88  }
89
90  // Prevents the supplied keys' IDs from being auto-allocated by Cloud
91  // Datastore.
92  rpc ReserveIds(ReserveIdsRequest) returns (ReserveIdsResponse) {
93    option (google.api.http) = {
94      post: "/v1beta3/projects/{project_id}:reserveIds"
95      body: "*"
96    };
97  }
98}
99
100// The request for
101// [Datastore.Lookup][google.datastore.v1beta3.Datastore.Lookup].
102message LookupRequest {
103  // The ID of the project against which to make the request.
104  string project_id = 8;
105
106  // The options for this lookup request.
107  ReadOptions read_options = 1;
108
109  // Keys of entities to look up.
110  repeated Key keys = 3;
111}
112
113// The response for
114// [Datastore.Lookup][google.datastore.v1beta3.Datastore.Lookup].
115message LookupResponse {
116  // Entities found as `ResultType.FULL` entities. The order of results in this
117  // field is undefined and has no relation to the order of the keys in the
118  // input.
119  repeated EntityResult found = 1;
120
121  // Entities not found as `ResultType.KEY_ONLY` entities. The order of results
122  // in this field is undefined and has no relation to the order of the keys
123  // in the input.
124  repeated EntityResult missing = 2;
125
126  // A list of keys that were not looked up due to resource constraints. The
127  // order of results in this field is undefined and has no relation to the
128  // order of the keys in the input.
129  repeated Key deferred = 3;
130}
131
132// The request for
133// [Datastore.RunQuery][google.datastore.v1beta3.Datastore.RunQuery].
134message RunQueryRequest {
135  // The ID of the project against which to make the request.
136  string project_id = 8;
137
138  // Entities are partitioned into subsets, identified by a partition ID.
139  // Queries are scoped to a single partition.
140  // This partition ID is normalized with the standard default context
141  // partition ID.
142  PartitionId partition_id = 2;
143
144  // The options for this query.
145  ReadOptions read_options = 1;
146
147  // The type of query.
148  oneof query_type {
149    // The query to run.
150    Query query = 3;
151
152    // The GQL query to run.
153    GqlQuery gql_query = 7;
154  }
155}
156
157// The response for
158// [Datastore.RunQuery][google.datastore.v1beta3.Datastore.RunQuery].
159message RunQueryResponse {
160  // A batch of query results (always present).
161  QueryResultBatch batch = 1;
162
163  // The parsed form of the `GqlQuery` from the request, if it was set.
164  Query query = 2;
165}
166
167// The request for
168// [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction].
169message BeginTransactionRequest {
170  // The ID of the project against which to make the request.
171  string project_id = 8;
172
173  // Options for a new transaction.
174  TransactionOptions transaction_options = 10;
175}
176
177// The response for
178// [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction].
179message BeginTransactionResponse {
180  // The transaction identifier (always present).
181  bytes transaction = 1;
182}
183
184// The request for
185// [Datastore.Rollback][google.datastore.v1beta3.Datastore.Rollback].
186message RollbackRequest {
187  // The ID of the project against which to make the request.
188  string project_id = 8;
189
190  // The transaction identifier, returned by a call to
191  // [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction].
192  bytes transaction = 1;
193}
194
195// The response for
196// [Datastore.Rollback][google.datastore.v1beta3.Datastore.Rollback]. (an empty
197// message).
198message RollbackResponse {}
199
200// The request for
201// [Datastore.Commit][google.datastore.v1beta3.Datastore.Commit].
202message CommitRequest {
203  // The modes available for commits.
204  enum Mode {
205    // Unspecified. This value must not be used.
206    MODE_UNSPECIFIED = 0;
207
208    // Transactional: The mutations are either all applied, or none are applied.
209    // Learn about transactions
210    // [here](https://cloud.google.com/datastore/docs/concepts/transactions).
211    TRANSACTIONAL = 1;
212
213    // Non-transactional: The mutations may not apply as all or none.
214    NON_TRANSACTIONAL = 2;
215  }
216
217  // The ID of the project against which to make the request.
218  string project_id = 8;
219
220  // The type of commit to perform. Defaults to `TRANSACTIONAL`.
221  Mode mode = 5;
222
223  // Must be set when mode is `TRANSACTIONAL`.
224  oneof transaction_selector {
225    // The identifier of the transaction associated with the commit. A
226    // transaction identifier is returned by a call to
227    // [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction].
228    bytes transaction = 1;
229  }
230
231  // The mutations to perform.
232  //
233  // When mode is `TRANSACTIONAL`, mutations affecting a single entity are
234  // applied in order. The following sequences of mutations affecting a single
235  // entity are not permitted in a single `Commit` request:
236  //
237  // - `insert` followed by `insert`
238  // - `update` followed by `insert`
239  // - `upsert` followed by `insert`
240  // - `delete` followed by `update`
241  //
242  // When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single
243  // entity.
244  repeated Mutation mutations = 6;
245}
246
247// The response for
248// [Datastore.Commit][google.datastore.v1beta3.Datastore.Commit].
249message CommitResponse {
250  // The result of performing the mutations.
251  // The i-th mutation result corresponds to the i-th mutation in the request.
252  repeated MutationResult mutation_results = 3;
253
254  // The number of index entries updated during the commit, or zero if none were
255  // updated.
256  int32 index_updates = 4;
257}
258
259// The request for
260// [Datastore.AllocateIds][google.datastore.v1beta3.Datastore.AllocateIds].
261message AllocateIdsRequest {
262  // The ID of the project against which to make the request.
263  string project_id = 8;
264
265  // A list of keys with incomplete key paths for which to allocate IDs.
266  // No key may be reserved/read-only.
267  repeated Key keys = 1;
268}
269
270// The response for
271// [Datastore.AllocateIds][google.datastore.v1beta3.Datastore.AllocateIds].
272message AllocateIdsResponse {
273  // The keys specified in the request (in the same order), each with
274  // its key path completed with a newly allocated ID.
275  repeated Key keys = 1;
276}
277
278// The request for
279// [Datastore.ReserveIds][google.datastore.v1beta3.Datastore.ReserveIds].
280message ReserveIdsRequest {
281  // The ID of the project against which to make the request.
282  string project_id = 8;
283
284  // If not empty, the ID of the database against which to make the request.
285  string database_id = 9;
286
287  // A list of keys with complete key paths whose numeric IDs should not be
288  // auto-allocated.
289  repeated Key keys = 1;
290}
291
292// The response for
293// [Datastore.ReserveIds][google.datastore.v1beta3.Datastore.ReserveIds].
294message ReserveIdsResponse {}
295
296// A mutation to apply to an entity.
297message Mutation {
298  // The mutation operation.
299  //
300  // For `insert`, `update`, and `upsert`:
301  // - The entity's key must not be reserved/read-only.
302  // - No property in the entity may have a reserved name,
303  //   not even a property in an entity in a value.
304  // - No value in the entity may have meaning 18,
305  //   not even a value in an entity in another value.
306  oneof operation {
307    // The entity to insert. The entity must not already exist.
308    // The entity key's final path element may be incomplete.
309    Entity insert = 4;
310
311    // The entity to update. The entity must already exist.
312    // Must have a complete key path.
313    Entity update = 5;
314
315    // The entity to upsert. The entity may or may not already exist.
316    // The entity key's final path element may be incomplete.
317    Entity upsert = 6;
318
319    // The key of the entity to delete. The entity may or may not already exist.
320    // Must have a complete key path and must not be reserved/read-only.
321    Key delete = 7;
322  }
323
324  // When set, the server will detect whether or not this mutation conflicts
325  // with the current version of the entity on the server. Conflicting mutations
326  // are not applied, and are marked as such in MutationResult.
327  oneof conflict_detection_strategy {
328    // The version of the entity that this mutation is being applied to. If this
329    // does not match the current version on the server, the mutation conflicts.
330    int64 base_version = 8;
331  }
332}
333
334// The result of applying a mutation.
335message MutationResult {
336  // The automatically allocated key.
337  // Set only when the mutation allocated a key.
338  Key key = 3;
339
340  // The version of the entity on the server after processing the mutation. If
341  // the mutation doesn't change anything on the server, then the version will
342  // be the version of the current entity or, if no entity is present, a version
343  // that is strictly greater than the version of any previous entity and less
344  // than the version of any possible future entity.
345  int64 version = 4;
346
347  // Whether a conflict was detected for this mutation. Always false when a
348  // conflict detection strategy field is not set in the mutation.
349  bool conflict_detected = 5;
350}
351
352// The options shared by read requests.
353message ReadOptions {
354  // The possible values for read consistencies.
355  enum ReadConsistency {
356    // Unspecified. This value must not be used.
357    READ_CONSISTENCY_UNSPECIFIED = 0;
358
359    // Strong consistency.
360    STRONG = 1;
361
362    // Eventual consistency.
363    EVENTUAL = 2;
364  }
365
366  // If not specified, lookups and ancestor queries default to
367  // `read_consistency`=`STRONG`, global queries default to
368  // `read_consistency`=`EVENTUAL`.
369  oneof consistency_type {
370    // The non-transactional read consistency to use.
371    // Cannot be set to `STRONG` for global queries.
372    ReadConsistency read_consistency = 1;
373
374    // The identifier of the transaction in which to read. A
375    // transaction identifier is returned by a call to
376    // [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction].
377    bytes transaction = 2;
378  }
379}
380
381// Options for beginning a new transaction.
382//
383// Transactions can be created explicitly with calls to
384// [Datastore.BeginTransaction][google.datastore.v1beta3.Datastore.BeginTransaction]
385// or implicitly by setting
386// [ReadOptions.new_transaction][google.datastore.v1beta3.ReadOptions.new_transaction]
387// in read requests.
388message TransactionOptions {
389  // Options specific to read / write transactions.
390  message ReadWrite {
391    // The transaction identifier of the transaction being retried.
392    bytes previous_transaction = 1;
393  }
394
395  // Options specific to read-only transactions.
396  message ReadOnly {}
397
398  // The `mode` of the transaction, indicating whether write operations are
399  // supported.
400  oneof mode {
401    // The transaction should allow both reads and writes.
402    ReadWrite read_write = 1;
403
404    // The transaction should only allow reads.
405    ReadOnly read_only = 2;
406  }
407}
408