For detailed explanation follow up DynamoDB NodeJS crud operations guide
Creating a table named Posts
with primary key postId
createTable('Posts', 'postId');
insertPost(
nanoid(),
'Learn to use DyanamoDB',
'Follow this to learn about DyanamoDB'
);
insertPost(
nanoid(),
'How to do CRUD operations in Dynamo?',
'It is not that hard to do CRUD operations in DynamoDB.'
);
insertPost(
nanoid(),
'Sample title that can be deleted',
'Sample description for the sample post'
);
getAllPosts('Posts');
Result:
{
"Items": [
{
"content": "Follow this to learn about DyanamoDB",
"postId": "DIylyPPcxYYc0vNsxjNUP",
"title": "Learn to use DyanamoDB"
},
{
"content": "Sample description for the sample post",
"postId": "UduchKnZN3boFSyPrASDz",
"title": "Sample title that can be deleted"
},
{
"content": "It is not that hard to do CRUD operations in DynamoDB.",
"postId": "IygP_2NLyoRxysBxals7O",
"title": "How to do CRUD operations in Dynamo?"
}
],
"Count": 3,
"ScannedCount": 3
}
getSinglePost('Posts', { postId: 'UduchKnZN3boFSyPrASDz' });
Result:
{
"Item": {
"content": "Sample description for the sample post",
"postId": "UduchKnZN3boFSyPrASDz",
"title": "Sample title that can be deleted"
}
}
updatePost(
'UduchKnZN3boFSyPrASDz',
'Update sample post title',
'Updated content'
);
deletePost('UduchKnZN3boFSyPrASDz');
{
Items: [
{
content: 'Follow this to learn about DyanamoDB',
postId: 'DIylyPPcxYYc0vNsxjNUP',
title: 'Learn to use DyanamoDB'
},
{
content: 'It is not that hard to do CRUD operations in DynamoDB.',
postId: 'IygP_2NLyoRxysBxals7O',
title: 'How to do CRUD operations in Dynamo?'
}
],
Count: 2,
ScannedCount: 2
}