amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Dynamo primary sort key

Open oste opened this issue 8 years ago • 22 comments

Is your feature request related to a problem? Please describe. amplify init and amplify push api commands don't allow for Dynamo tables to be created with a sort key.

Describe the solution you'd like There was some discussion here of a possible solution but it doesn't seem to be implemented yet https://github.com/aws-amplify/amplify-cli/issues/56#issuecomment-416736520

Also discussed here https://github.com/aws-amplify/amplify-cli/pull/277#issuecomment-428690938

Something like this seems like it would work for my case of needing a sort key on a timestamp

type DeviceData @model {
  id: ID!
  timestamp: String! @sort
  value: String!
}

Describe alternatives you've considered Not aware of any, would be open to anything since sort keys cannot be added to already created Dynamo tables.

oste avatar Nov 21 '18 03:11 oste

I would like to second this request

cityzen avatar Dec 03 '18 16:12 cityzen

Thank you for the note. This is a highly request feature and your feedback really helps us prioritize it. I will make sure this is included in discussions and will report back when I have more details.

mikeparisstuff avatar Dec 04 '18 21:12 mikeparisstuff

Would just like add that our organization would also love to see this feature. As it currently stands, we're going to have to try manually modifying the cloudformation template that amplify creates in order to adjust the partition and sort keys.

zjullion avatar Dec 04 '18 22:12 zjullion

@zjullion I think you can link into an existing table or manually create a table and write your own custom resolvers. It may be easier to just form your own dynamo tables and write the custom resolvers than trying to fiddle with the auto-generated CloudFormation template.

cityzen avatar Dec 04 '18 23:12 cityzen

This is definitely our most needed feature at the moment. Would it be feasible to support specifying multiple sort fields? Example: sorting on createdAt or updatedAt. Clients would then specify what sort type to use in their graphql query variables.

mart2967 avatar Dec 09 '18 23:12 mart2967

I also have the same need to filter on createdAt or any other field, would be great to have that available soon.

rpostulart avatar Feb 04 '19 14:02 rpostulart

+1 We also really need the feature.

toddsampson avatar Feb 27 '19 05:02 toddsampson

Wanted to ping this ticket again. We are working on an RFC for custom indexes on @model types and would love to hear your feedback when it is posted to GH.

mikeparisstuff avatar Feb 28 '19 00:02 mikeparisstuff

@mikeparisstuff would be great to have a way not only specify sort key but partition too.

sakhmedbayev avatar Feb 28 '19 01:02 sakhmedbayev

+1 We really need the feature also

laura-sainz-mojix-com avatar Mar 07 '19 15:03 laura-sainz-mojix-com

+1 It would be great to have this feature.

watanabethais avatar Mar 12 '19 05:03 watanabethais

+1

peterdyer7 avatar Mar 14 '19 17:03 peterdyer7

+1

AlirezaAsadi avatar Mar 15 '19 16:03 AlirezaAsadi

+1

marcschroeter avatar Apr 19 '19 19:04 marcschroeter

What is the best temporary way to sort createdAt?

Looks like difficult to sort all data, so easy way to achieve this (not using console ) maybe making (dummy) table and connect it to the table which want to be sorted using @connection(name: String, keyField: String, sortField: String).

or add some kind of metafield to table and use it as a partition key and use createdAt as sort key. (in this case, have to add gsi from console and maybe have to add resolver.)

type Post @model {
    id: ID!
    title: String
    creaatedAt: AWSDateTime // sort-key
    metadata: MetaData  // partion-key
}
type MetaData {
    category: Category
}
enum Category { comedy news }

or use ElasticSearch for sorting.

yareyaredesuyo avatar May 10 '19 19:05 yareyaredesuyo

How is this still not resolved? This seems like it should be trivial. We need to define 1 to many relationships (user videos) and require a sort key.

et304383 avatar May 17 '19 12:05 et304383

+1

Crisp3333 avatar May 29 '19 19:05 Crisp3333

Currently for sorting, I am getting the query back from the response in call back then creating my own sorting algorithm. I think sorting is a fundamental operation for database/querying, it might not be core, but it is used so much that it seems core. I rather not use this @index implementation to interfere with schemas that I am already satisfied with. To my benefit I am only returning at most 20 results. If it was 100's or 1000's of data to sort I would be in big problem. But sorting is needed. Would appreciate if some sorting mechanism would be provided out of the box for appsync\graphql

Crisp3333 avatar May 29 '19 20:05 Crisp3333

We launched support for custom indexes today. You can find docs for the same out here - https://aws-amplify.github.io/docs/cli/graphql#key Please let us know if you're still not able to solve your problem through this solution and we'll re-open this issue for you.

kaustavghosh06 avatar May 30 '19 05:05 kaustavghosh06

Awesome work! 👍

AlirezaAsadi avatar May 30 '19 05:05 AlirezaAsadi