1- // Copyright 2024 Google LLC
1+ // Copyright 2025 Google LLC
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
@@ -24,13 +24,15 @@ import (
2424"cloud.google.com/go/spanner"
2525)
2626
27- // rwTxnExcludedFromChangeStreams executes the insert and update DMLs on Singers table excluded from allowed tracking change streams
28- func rwTxnExcludedFromChangeStreams (w io.Writer , db string ) error {
27+ // readWriteTxnExcludedFromChangeStreams executes the insert and update DMLs on
28+ // Singers table excluded from tracking change streams with ddl option
29+ // allow_txn_exclusion = true.
30+ func readWriteTxnExcludedFromChangeStreams (w io.Writer , db string ) error {
2931// db = `projects/<project>/instances/<instance-id>/database/<database-id>`
3032ctx := context .Background ()
3133client , err := spanner .NewClient (ctx , db )
3234if err != nil {
33- return fmt .Errorf ("rwTxnExcludedFromChangeStreams .NewClient: %w" , err )
35+ return fmt .Errorf ("readWriteTxnExcludedFromChangeStreams .NewClient: %w" , err )
3436}
3537defer client .Close ()
3638
@@ -41,15 +43,15 @@ func rwTxnExcludedFromChangeStreams(w io.Writer, db string) error {
4143}
4244_ , err := txn .Update (ctx , stmt )
4345if err != nil {
44- return fmt .Errorf ("rwTxnExcludedFromChangeStreams .Update: %w" , err )
46+ return fmt .Errorf ("readWriteTxnExcludedFromChangeStreams .Update: %w" , err )
4547}
46- fmt .Fprintf (w , "New singer inserted." )
48+ fmt .Fprintln (w , "New singer inserted." )
4749stmt = spanner.Statement {
4850SQL : `UPDATE Singers SET FirstName = 'Hi' WHERE SingerId = 111` ,
4951}
5052_ , err = txn .Update (ctx , stmt )
5153if err != nil {
52- return fmt .Errorf ("rwTxnExcludedFromChangeStreams .Update: %w" , err )
54+ return fmt .Errorf ("readWriteTxnExcludedFromChangeStreams .Update: %w" , err )
5355}
5456fmt .Fprint (w , "Singer first name updated." )
5557return nil
0 commit comments