fsprojects / FSharp.AWS.DynamoDB

F# wrapper API for AWS DynamoDB
MIT License
58 stars 18 forks source link

Hash/sort keys and GSI hash/sort keys can not be set on same field #36

Closed purkhusid closed 9 months ago

purkhusid commented 3 years ago

I'm trying to create a table that has a GSI with the Hash key and Sort key inverted.

The way I would do it is that I have the following record:

type TableItem =
    { [<HashKey>]
      [<GlobalSecondaryRangeKey(indexName = "Inverted")>]
      PrimaryKey: string
      [<RangeKey>]
      [<GlobalSecondaryHashKey(indexName = "Inverted")>]
      SortKey: string
      Model: Model }

This fails when doing a query by the GSI hash key and sort key because of this check: https://github.com/purkhusid/FSharp.AWS.DynamoDB/blob/710558033727f9cab1a7c1917146fc1cb5c5485b/src/FSharp.AWS.DynamoDB/TableContext.fs#L80-L80

I don't see any reason for not allowing this type of record since this is a very common thing to do with DynamoDB.

I could take a stab at fixing this if you would be OK with the change.

samritchie commented 3 years ago

There may be a possible issue with ambiguity as to which index corresponds to a query, but I think we should be able to determine the correct one based on the query expression. Do you want to have a go at doing a PR - maybe do some query expression tests to try and verify queries select the correct inverted index?

purkhusid commented 3 years ago

I'll try to find some time soon to take a look at this then.