Garry S
Garry S

Reputation: 117

convert mysql table to DynamoDB

I'm new to DynamoDB and I'm trying to get the hang of it but I'm not getting how to maintain relation in single table DynamoDB.

Basically I am executing script & dynamically adding data into table.

First I am adding entry in run master & take id from it & add multiple entries detailedruninfo along with run_id from master table. below are mysql table data:

run_master table (id is PK)
+----+-------------------------------+
| id | user_id |  add_date           |  
+----+---------+---------------------+
| 1  | 1       |2022-09-23 11:04:06  | 
+----+---------+---------------------+
| 2  | 1       |2021-09-25 01:37:41  |
+----+---------+---------------------+
| 3  | 2       |2021-10-03 06:29:16  |
+----+---------+---------------------+

run_details table (run_id is FK)
+----+---------+------------+---------+
| id |  run_id | track_name |  status |
+----+---------+------------+---------+
| 1  | 1       | track1     | fail    |
+----+---------+------------+---------+
| 2  | 1       | track2     | pass    |
+----+---------+------------+---------+
| 3  | 1       | track3     | fail    |
+----+---------+------------+---------+
| 4  | 2       | us         | pass    |
+----+---------+------------+---------+
| 5  | 3       | it         | pass    |
+----+---------+------------+---------+

I know if run master table entries are fixed then I can directly add column in run_details table but I am inserting data into loop for both table.

how to create table in dynamoDb and what would be the query if I want to get all records from run_details by Run Id?

Upvotes: 0

Views: 89

Answers (1)

Leeroy Hannigan
Leeroy Hannigan

Reputation: 19883

I'm guessing here that the combination of run_id and add_date is unique, for that reason I have used those as PK and SK respectively.

The below table allows you to get all runs for a given run_id by using a Query operation and providing the run_id.

id is not needed here, as it serves no purpose.

+--------+----------------------+------------+---------+---------+
| run_id | add_date             | track_name |  status | user_id |
+--------+----------------------+------------+---------+---------+
| 1      | 2022-09-23 11:04:06  | track1     | fail    |  1      |
+--------+----------------------+------------+---------+---------+
| 1      | 2022-09-23 11:04:06  | track2     | pass    |  1      |
+--------+----------------------+------------+---------+---------+
| 1      | 2022-09-23 11:04:06  | track3     | fail    |  1      |
+--------+----------------------+------------+---------+---------+
| 2      | 2022-09-23 11:04:06  | us         | pass    |  2      |
+--------+----------------------+------------+---------+---------+
| 3      | 2022-09-23 11:04:06  | it         | pass    |  3      |
+--------+----------------------+------------+---------+---------+

You can also create an index on user_id should you wish to get all runs by user etc...

Upvotes: 1

Related Questions