MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / readRowByKeyWithTransaction

Method readRowByKeyWithTransaction

lib/gcpspanner/client.go:825–852  ·  view source on GitHub ↗

readRowByKey retrieves the row of an entity based on its external key with transaction.

(
	ctx context.Context,
	key Key,
	txn transaction,
)

Source from the content-addressed store, hash-verified

823
824// readRowByKey retrieves the row of an entity based on its external key with transaction.
825func (c *entityReader[M, ExternalStruct, SpannerStruct, Key]) readRowByKeyWithTransaction(
826 ctx context.Context,
827 key Key,
828 txn transaction,
829) (*SpannerStruct, error) {
830 var mapper M
831 stmt := mapper.SelectOne(key)
832 // Attempt to query for the row.
833 it := txn.Query(ctx, stmt)
834 defer it.Stop()
835 row, err := it.Next()
836 if err != nil {
837 // No row found
838 if errors.Is(err, iterator.Done) {
839 return nil, errors.Join(ErrQueryReturnedNoResults, err)
840 }
841
842 // Catch-all for other errors.
843 return nil, errors.Join(ErrInternalQueryFailure, err)
844 }
845 existing := new(SpannerStruct)
846 err = row.ToStruct(existing)
847 if err != nil {
848 return nil, errors.Join(ErrInternalQueryFailure, err)
849 }
850
851 return existing, nil
852}
853
854func (c *entityWriterWithIDRetrieval[M, ExternalStruct, SpannerStruct, Key, ID]) getIDByKey(
855 ctx context.Context,

Calls 2

SelectOneMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected