Skip to content

Commit ba0ad58

Browse files
committed
Allow reading values based on cosmosID when that cosmosID is the resourceID
ResourceID is tolowered and then swap / for | to make a valid cosmosID.
1 parent d1a8c74 commit ba0ad58

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

internal/database/crud_helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ func getByItemID[InternalAPIType, CosmosAPIType any](ctx context.Context, contai
6262
}
6363

6464
func get[InternalAPIType, CosmosAPIType any](ctx context.Context, containerClient *azcosmos.ContainerClient, partitionKeyString string, completeResourceID *azcorearm.ResourceID) (*InternalAPIType, error) {
65+
// try to see if the cosmosID we've passed is also the exact resource ID. If so, then return the value we got.
66+
if exactCosmosID, err := resourceIDToCosmosID(completeResourceID); err == nil {
67+
ret, err := getByItemID[InternalAPIType, CosmosAPIType](ctx, containerClient, partitionKeyString, exactCosmosID)
68+
if err == nil {
69+
return ret, nil
70+
}
71+
if !IsResponseError(err, http.StatusNotFound) {
72+
return nil, err
73+
}
74+
}
75+
6576
if strings.ToLower(partitionKeyString) != partitionKeyString {
6677
return nil, fmt.Errorf("partitionKeyString must be lowercase, not: %q", partitionKeyString)
6778
}

0 commit comments

Comments
 (0)