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

@@ -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 {

0 comments on commit c276428

Please sign in to comment.