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 15syntax = "proto3"; 16 17package google.spanner.v1; 18 19import "google/api/field_behavior.proto"; 20import "google/protobuf/struct.proto"; 21import "google/spanner/v1/keys.proto"; 22 23option csharp_namespace = "Google.Cloud.Spanner.V1"; 24option go_package = "cloud.google.com/go/spanner/apiv1/spannerpb;spannerpb"; 25option java_multiple_files = true; 26option java_outer_classname = "MutationProto"; 27option java_package = "com.google.spanner.v1"; 28option php_namespace = "Google\\Cloud\\Spanner\\V1"; 29option ruby_package = "Google::Cloud::Spanner::V1"; 30 31// A modification to one or more Cloud Spanner rows. Mutations can be 32// applied to a Cloud Spanner database by sending them in a 33// [Commit][google.spanner.v1.Spanner.Commit] call. 34message Mutation { 35 // Arguments to [insert][google.spanner.v1.Mutation.insert], [update][google.spanner.v1.Mutation.update], [insert_or_update][google.spanner.v1.Mutation.insert_or_update], and 36 // [replace][google.spanner.v1.Mutation.replace] operations. 37 message Write { 38 // Required. The table whose rows will be written. 39 string table = 1 [(google.api.field_behavior) = REQUIRED]; 40 41 // The names of the columns in [table][google.spanner.v1.Mutation.Write.table] to be written. 42 // 43 // The list of columns must contain enough columns to allow 44 // Cloud Spanner to derive values for all primary key columns in the 45 // row(s) to be modified. 46 repeated string columns = 2; 47 48 // The values to be written. `values` can contain more than one 49 // list of values. If it does, then multiple rows are written, one 50 // for each entry in `values`. Each list in `values` must have 51 // exactly as many entries as there are entries in [columns][google.spanner.v1.Mutation.Write.columns] 52 // above. Sending multiple lists is equivalent to sending multiple 53 // `Mutation`s, each containing one `values` entry and repeating 54 // [table][google.spanner.v1.Mutation.Write.table] and [columns][google.spanner.v1.Mutation.Write.columns]. Individual values in each list are 55 // encoded as described [here][google.spanner.v1.TypeCode]. 56 repeated google.protobuf.ListValue values = 3; 57 } 58 59 // Arguments to [delete][google.spanner.v1.Mutation.delete] operations. 60 message Delete { 61 // Required. The table whose rows will be deleted. 62 string table = 1 [(google.api.field_behavior) = REQUIRED]; 63 64 // Required. The primary keys of the rows within [table][google.spanner.v1.Mutation.Delete.table] to delete. The 65 // primary keys must be specified in the order in which they appear in the 66 // `PRIMARY KEY()` clause of the table's equivalent DDL statement (the DDL 67 // statement used to create the table). 68 // Delete is idempotent. The transaction will succeed even if some or all 69 // rows do not exist. 70 KeySet key_set = 2 [(google.api.field_behavior) = REQUIRED]; 71 } 72 73 // Required. The operation to perform. 74 oneof operation { 75 // Insert new rows in a table. If any of the rows already exist, 76 // the write or transaction fails with error `ALREADY_EXISTS`. 77 Write insert = 1; 78 79 // Update existing rows in a table. If any of the rows does not 80 // already exist, the transaction fails with error `NOT_FOUND`. 81 Write update = 2; 82 83 // Like [insert][google.spanner.v1.Mutation.insert], except that if the row already exists, then 84 // its column values are overwritten with the ones provided. Any 85 // column values not explicitly written are preserved. 86 // 87 // When using [insert_or_update][google.spanner.v1.Mutation.insert_or_update], just as when using [insert][google.spanner.v1.Mutation.insert], all `NOT 88 // NULL` columns in the table must be given a value. This holds true 89 // even when the row already exists and will therefore actually be updated. 90 Write insert_or_update = 3; 91 92 // Like [insert][google.spanner.v1.Mutation.insert], except that if the row already exists, it is 93 // deleted, and the column values provided are inserted 94 // instead. Unlike [insert_or_update][google.spanner.v1.Mutation.insert_or_update], this means any values not 95 // explicitly written become `NULL`. 96 // 97 // In an interleaved table, if you create the child table with the 98 // `ON DELETE CASCADE` annotation, then replacing a parent row 99 // also deletes the child rows. Otherwise, you must delete the 100 // child rows before you replace the parent row. 101 Write replace = 4; 102 103 // Delete rows from a table. Succeeds whether or not the named 104 // rows were present. 105 Delete delete = 5; 106 } 107} 108