loading...

re: Consider DynamoDB for your next project VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Nice article, but I'm a bit confused about the last access pattern (getting the users that liked a post): wouldn't we have to update the transact...
 

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 🙂.
 
code of conduct - report abuse