DEV Community

Discussion on: Consider DynamoDB for your next project

Collapse
 
fampinheiro profile image
Filipe Pinheiro • Edited

Yes, I haven't included the attribute properties when Puting an object.
On the Item property we would need to specify the attributes for the different types.

In the case of a Post:

Item: {
  PK: { S: `TOPIC#<TOPIC>` },
  SK: { S: `POST#<KSUID>` },
  GSI1PK: { S: `POST#<KSUID>` },
  GSI1SK: { S: `POST#<KSUID>` },
  type: "POST",
  nrLikes: 0
}

And for the Like:

Item: {
  PK: { S: `USER#<USERNAME>` },
  SK: { S: `LIKEPOST#<USERNAME>` },
  GSI1PK: { S: `POST#<KSUID>` },
  GSI1SK: { S: `LIKEPOST#<USERNAME>` },
  type: "LIKE"
}

In case you already have items on your table you need a migration.
Depending on your use case:

  • You can use Scan method to migrate every entry;
  • Update POST entries when you have the first like;
  • You can use another creative method 🙂.
Collapse
 
vladcostea profile image
Vlad Costea

brilliant, thanks :)