spanner: ReadOnlyTransaction().ReadRowUsingIndex() #1035
Labels
api: spanner
Issues related to the Spanner API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
ReadRow
is useful method for getting a single row. However, if you want to get all the columns of a single row using an index (a common case for unique fields, like, say finding a user by username), it's much harder. ReadUsingIndex requires that you defineSTORING
for every column name, which is duplicative and brittle to maintain (remembering to add every new column as you go*) .The alternative is to use a
SELECT ... {FORCE_INDEX=index}
statement, and callQuery
. Both this andReadUsingIndex
require the handling of an iterator which you need to process for just a single item, iterator.Done for Not Found etc.It would be helpful if the APIs for such similar queries weren't so wildly different.
I would like to see
ReadRowUsingIndex
, which under the hood did the same kind of join asSELECT {FORCE_INDEX}
query does, and which returns a single row (technically the first) as a result. I wouldn't even mind if it was enforced that you could only call this on aUNIQUE
index. This would dramatically reduce boilerplate, which already has to be quite substantial due to Go's lack of generics.--
(* meta-point, for those cases where I really do want to do this, I'd love to see a language extension like
STORING ALL
or something similar. DynamoDB offers this for its Global Indices, for example.)The text was updated successfully, but these errors were encountered: