googleapis / googleapis/google-cloud-go

spanner: add (Batch)?Update(WithOptions)? to Client

Open
#9,583 5 comments 0 reactions 1 assignee Claimed by @rahul2393 View on GitHub
api: spanner needs more info type: feature request
Dominant language
Go
Stars
4.5k
Forks
1.6k
Avg merge
1d 13h
Merged PRs (30d)
109

Description

**Is your feature request related to a problem? Please describe.**
If a ReadWriteTransaction needs to perform only a batch of one or more update operations, it is wasteful and unneccessary to keep the transaction open for an extra roundtrip.

**Describe the solution you'd like**

Add the following methods to spanner.Client:

```
Update(ctx context.Context, stmt Statement) (rowCount int64, err error)
UpdateWithOptions(ctx context.Context, stmt Statement, opts QueryOptions) (rowCount int64, err error)
BatchUpdate(ctx context.Context, stmts []Statement) (rowCounts []int64, err error)
BatchUpdateWithOptions(ctx context.Context, stmts []Statement, opts QueryOptions) (rowCounts []int64, err error)
```

that would behave as a ReadWriteTransaction containing a single call to corresponding method above, so e.g.

```
rowCount, err := client.Update(ctx, stmt)
```

would behave as

```
var rowCount int
err := client.ReadWriteTransaction(ctx, func(ctx context.Context, rwt *spanner.ReadWriteTransaction) (err error) {
rowCount, err = rwt.Update(ctx, stmt)
return
})
```

but allowing Spanner to close the transaction as soon as the update completes, without waiting for the client to explicitly commit.

**Describe alternatives you've considered**
The equivalent code above works today, but is less efficient.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.