1
00:00:00,150 --> 00:00:04,350
In this video, we are going to update an item into dynamic TV tables.

2
00:00:04,890 --> 00:00:12,450
So we will implement these use case files, update item in dynamic TV table to perform update item command.

3
00:00:12,690 --> 00:00:16,320
So in order to do that, please open the SDK documentation.

4
00:00:16,320 --> 00:00:23,460
And if you search for the update item, if you go to command, you can see the example usage.

5
00:00:23,460 --> 00:00:27,860
We will use update item command and to see input parameters.

6
00:00:27,870 --> 00:00:31,690
It is a bit confusing if you open the update item command.

7
00:00:31,710 --> 00:00:36,390
There are some properties that we can that we can use when updating an item.

8
00:00:36,390 --> 00:00:40,530
So the important one is the table name and the key information.

9
00:00:40,530 --> 00:00:46,200
In the key information, we should provide the ID as a number for the partition and primary key.

10
00:00:46,200 --> 00:00:50,670
And after that we will use the update expression.

11
00:00:50,670 --> 00:00:55,830
So in the update expression, we should give the which attribute we are going to update.

12
00:00:55,830 --> 00:01:00,930
And after that we should give the values and the names from the expression attribute values.

13
00:01:00,960 --> 00:01:04,560
Let me develop and show how we can update an existing item.

14
00:01:04,710 --> 00:01:05,940
Are using the HDC.

15
00:01:05,940 --> 00:01:09,810
So in order to do that, please open the Visual Studio code.

16
00:01:09,810 --> 00:01:17,910
And in this file, as you can see that I have created update item JS file, that is implementation of

17
00:01:17,910 --> 00:01:19,170
update item command.

18
00:01:19,170 --> 00:01:21,120
So let me explain one by one.

19
00:01:21,120 --> 00:01:27,810
But before explaining this file, I have also created a template JS file which including our template

20
00:01:27,810 --> 00:01:30,860
code operations when it comes to interacting dynamic.

21
00:01:30,870 --> 00:01:37,830
DB So as you can see that we have run method in here and in the drive look we will implement these dynamic

22
00:01:37,830 --> 00:01:42,450
DB send operation according to command that we are going to implement.

23
00:01:42,450 --> 00:01:44,880
So it is also taking parameters.

24
00:01:44,880 --> 00:01:52,230
So we have also parameters object defined in here and these parameters attributes differentiate based

25
00:01:52,230 --> 00:01:53,790
on the different commands.

26
00:01:53,790 --> 00:01:56,640
So you can see that we have also import statement.

27
00:01:56,640 --> 00:02:03,060
So I'm going to use this template for every command window and this time we are going to update item

28
00:02:03,060 --> 00:02:07,800
and see that update item has also actual code operation in here.

29
00:02:07,800 --> 00:02:13,470
We basically use dynamic DB client and we sent update item command with these parameters.

30
00:02:13,470 --> 00:02:18,960
So first of all, we should import update item command and dynamic DB client object.

31
00:02:18,960 --> 00:02:23,100
And after that we will prepare the parameters as per the documentation.

32
00:02:23,100 --> 00:02:26,220
This is very important to set correct parameters.

33
00:02:26,220 --> 00:02:31,650
So how we can define these parameters, of course we will check the SDK documentation.

34
00:02:31,650 --> 00:02:34,290
And also I would like to show one more thing.

35
00:02:34,470 --> 00:02:42,600
Maybe you remember in lecture 138, we have also performed the same action with using the same commands.

36
00:02:42,600 --> 00:02:48,780
So if you can see that we are using the update item, select command specifying these attributes.

37
00:02:48,780 --> 00:02:55,650
So I have specified exactly the same attributes which are the table name, key update, expression,

38
00:02:55,650 --> 00:02:58,770
expression, attribute, values and so on.

39
00:02:58,770 --> 00:03:07,260
So I will follow the same configuration into our update item JS and the parameters you can see find

40
00:03:07,260 --> 00:03:08,040
in here.

41
00:03:08,040 --> 00:03:16,350
So before starting these parameters, I would like to emphasize that we basically specifying table name

42
00:03:16,350 --> 00:03:23,550
and key information, which is the ID of our product table and update in the update expression, we

43
00:03:23,550 --> 00:03:30,150
have set the product name as any world and in the expression attribute values we have give the actual

44
00:03:30,150 --> 00:03:37,920
value which be we would like to update these attribute name and we should also provide the string parameter

45
00:03:37,920 --> 00:03:39,510
name as object format.

46
00:03:39,510 --> 00:03:45,870
So this is very important to be in the same configuration, otherwise it gets lots of exception.

47
00:03:45,870 --> 00:03:51,000
So please make sure that, for example, the attribute name should be product name.

48
00:03:51,180 --> 00:03:58,380
The previous version we set the name and it is a resort keywords that is throwing an exception.

49
00:03:58,380 --> 00:04:01,830
So that's why I have to change the attribute name as a product name.

50
00:04:01,830 --> 00:04:06,270
For that purpose we have to write item again if you open the right item.

51
00:04:06,270 --> 00:04:11,880
JS You can see that in the last video we have write item in this format.

52
00:04:11,880 --> 00:04:17,160
So I changed the name as a product name and the ID could be only one.

53
00:04:17,430 --> 00:04:21,000
Save this file and I'm going to write again this file.

54
00:04:21,000 --> 00:04:24,720
But before that let's remove the old one for that purpose.

55
00:04:24,750 --> 00:04:28,980
Go to Dynamic DB, explore items and delete this item.

56
00:04:30,770 --> 00:04:37,610
And now I will come back to our record and continue with writing this item with the attribute name as

57
00:04:37,610 --> 00:04:38,480
a product name.

58
00:04:38,570 --> 00:04:43,580
So for that purpose, run the command node, write item, hit enter.

59
00:04:44,060 --> 00:04:50,990
So this is write an item if you want the scan command, see that this time we have create an item with

60
00:04:50,990 --> 00:04:52,860
the attribute name as a product name.

61
00:04:52,880 --> 00:05:00,620
So if you come back to our update item operation, so make sure that your parameters is exactly same.

62
00:05:00,620 --> 00:05:09,620
And if you come to command window and run the node update item JS file, hit the enter.

63
00:05:09,950 --> 00:05:14,270
So this time we have update the product name as we expected.

64
00:05:14,270 --> 00:05:22,310
And if you come back to the our DB console and run the scan command, see that this attribute value

65
00:05:22,340 --> 00:05:24,620
is updated within the name.

66
00:05:24,860 --> 00:05:30,020
So as you can see that we have successfully update our existing data.

67
00:05:30,050 --> 00:05:35,510
In the next video we are going to getting an item with using the Dynamo DB SDK commands.
