Skip to content

Commit

Permalink
feat(spanner): Add ReadRowWithOptions method (#5240)
Browse files Browse the repository at this point in the history
Co-authored-by: rahul2393 <rahulyadavsep92@gmail.com>
  • Loading branch information
shuheiktgw and rahul2393 committed Dec 29, 2021
1 parent 974acd8 commit c276428
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit c276428

Please sign in to comment.