readRowByKey retrieves the row of an entity based on its external key with transaction.
( ctx context.Context, key Key, txn transaction, )
| 823 | |
| 824 | // readRowByKey retrieves the row of an entity based on its external key with transaction. |
| 825 | func (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 | |
| 854 | func (c *entityWriterWithIDRetrieval[M, ExternalStruct, SpannerStruct, Key, ID]) getIDByKey( |
| 855 | ctx context.Context, |
no test coverage detected