datastore.proto 19 KB

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