datastore.proto 14 KB

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