Populate tables with sample data.
(client)
| 192 | # --------------------------------------------------------------------------- |
| 193 | |
| 194 | def load_data(client) -> None: |
| 195 | """Populate tables with sample data.""" |
| 196 | section("Step 3: Load Data (PutItem + BatchWriteItem)") |
| 197 | |
| 198 | # PutItem — individual user profiles |
| 199 | users = [ |
| 200 | {"userId": "user-001", "name": "Alice", "email": "alice@example.com", "age": 30}, |
| 201 | {"userId": "user-002", "name": "Bob", "email": "bob@example.com", "age": 25}, |
| 202 | {"userId": "user-003", "name": "Charlie", "email": "charlie@example.com", "age": 35}, |
| 203 | ] |
| 204 | for u in users: |
| 205 | client.put_item( |
| 206 | TableName=USERS_TABLE, |
| 207 | Item={ |
| 208 | "userId": {"S": u["userId"]}, |
| 209 | "name": {"S": u["name"]}, |
| 210 | "email": {"S": u["email"]}, |
| 211 | "age": {"N": str(u["age"])}, |
| 212 | }, |
| 213 | ) |
| 214 | print(f" ✓ Loaded {len(users)} users via PutItem") |
| 215 | |
| 216 | # BatchWriteItem — orders |
| 217 | orders = [ |
| 218 | {"customerId": "user-001", "orderId": "ord-101", "orderDate": "2026-01-15", "total": "29.99", "status": "delivered"}, |
| 219 | {"customerId": "user-001", "orderId": "ord-102", "orderDate": "2026-02-20", "total": "149.50", "status": "shipped"}, |
| 220 | {"customerId": "user-001", "orderId": "ord-103", "orderDate": "2026-03-10", "total": "9.99", "status": "pending"}, |
| 221 | {"customerId": "user-002", "orderId": "ord-201", "orderDate": "2026-01-05", "total": "75.00", "status": "delivered"}, |
| 222 | {"customerId": "user-002", "orderId": "ord-202", "orderDate": "2026-03-01", "total": "200.00", "status": "shipped"}, |
| 223 | {"customerId": "user-003", "orderId": "ord-301", "orderDate": "2026-02-14", "total": "45.00", "status": "delivered"}, |
| 224 | ] |
| 225 | put_requests = [ |
| 226 | { |
| 227 | "PutRequest": { |
| 228 | "Item": { |
| 229 | "customerId": {"S": o["customerId"]}, |
| 230 | "orderId": {"S": o["orderId"]}, |
| 231 | "orderDate": {"S": o["orderDate"]}, |
| 232 | "total": {"N": o["total"]}, |
| 233 | "status": {"S": o["status"]}, |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | for o in orders |
| 238 | ] |
| 239 | client.batch_write_item(RequestItems={ORDERS_TABLE: put_requests}) |
| 240 | print(f" ✓ Loaded {len(orders)} orders via BatchWriteItem") |
| 241 | |
| 242 | # BatchWriteItem — tournament matches |
| 243 | matches = [ |
| 244 | {"matchId": "m-001", "tournamentId": "T2026-Spring", "region": "NA", "round": 1, "bracket": "A", "player1Id": "user-001", "player2Id": "user-002", "matchDate": "2026-03-01", "score": "3-1"}, |
| 245 | {"matchId": "m-002", "tournamentId": "T2026-Spring", "region": "NA", "round": 1, "bracket": "B", "player1Id": "user-003", "player2Id": "user-001", "matchDate": "2026-03-01", "score": "2-3"}, |
| 246 | {"matchId": "m-003", "tournamentId": "T2026-Spring", "region": "NA", "round": 2, "bracket": "A", "player1Id": "user-001", "player2Id": "user-003", "matchDate": "2026-03-02", "score": "3-0"}, |
| 247 | {"matchId": "m-004", "tournamentId": "T2026-Spring", "region": "EU", "round": 1, "bracket": "A", "player1Id": "user-002", "player2Id": "user-003", "matchDate": "2026-03-01", "score": "1-3"}, |
| 248 | {"matchId": "m-005", "tournamentId": "T2026-Summer", "region": "NA", "round": 1, "bracket": "A", "player1Id": "user-001", "player2Id": "user-002", "matchDate": "2026-06-15", "score": "3-2"}, |
| 249 | ] |
| 250 | match_requests = [ |
| 251 | { |