Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(spanner): Add ReadRowWithOptions method #5240

Merged
merged 2 commits into from Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions spanner/client_test.go
Expand Up @@ -2860,6 +2860,21 @@ func TestClient_Single_Read_WithNumericKey(t *testing.T) {
}
}

func TestClient_Single_ReadRowWithOptions(t *testing.T) {
t.Parallel()

_, client, teardown := setupMockedTestServer(t)
defer teardown()
ctx := context.Background()
row, err := client.Single().ReadRowWithOptions(ctx, "Albums", Key{"foo"}, []string{"SingerId", "AlbumId", "AlbumTitle"}, &ReadOptions{RequestTag: "foo/bar"})
if err != nil {
t.Fatalf("Unexpected error for read row with options: %v", err)
}
if row == nil {
t.Fatal("ReadRowWithOptions did not return a row")
}
}

func TestClient_CloseWithUnresponsiveBackend(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 9 additions & 1 deletion spanner/transaction.go
Expand Up @@ -212,7 +212,15 @@ func errMultipleRowsFound(table string, key Key, index string) error {
// If no row is present with the given key, then ReadRow returns an error where
// spanner.ErrCode(err) is codes.NotFound.
func (t *txReadOnly) ReadRow(ctx context.Context, table string, key Key, columns []string) (*Row, error) {
iter := t.Read(ctx, table, key, columns)
return t.ReadRowWithOptions(ctx, table, key, columns, nil)
}

// ReadRowWithOptions reads a single row from the database. Pass a ReadOptions to modify the read operation.
//
// If no row is present with the given key, then ReadRowWithOptions returns an error where
// spanner.ErrCode(err) is codes.NotFound.
func (t *txReadOnly) ReadRowWithOptions(ctx context.Context, table string, key Key, columns []string, opts *ReadOptions) (*Row, error) {
iter := t.ReadWithOptions(ctx, table, key, columns, opts)
defer iter.Stop()
row, err := iter.Next()
switch err {
Expand Down