// Define the structure for a cart item
interface CartItem {
productId: number;
quantity: number;
}
// Define the structure for a user cart
interface UserCart {
userId: string;
items: CartItem[];
}
// Define the structure for a user
interface User {
id: string;
name: string;
email: string;
cart: UserCart;
}
// Create a user object that includes the cart
const user: User = {
id: 'user123',
name: 'John Doe',
email: 'john.doe@example.com',
cart: {
userId: 'user123',
items: [
{ productId: 1, quantity: 2 },
{ productId: 3, quantity: 1 }
]
}
};
console.log(user);
id,name,price,description,in_stock
1,Super Dog Cape,19.99,A red cape for your super dog!,true
2,Dog Wizard Hat,9.99,Magical hat for spell-casting pups!,true
3,Puppy Pirate Eye Patch,4.99,For the adventurous sea-faring pup!,true
4,Canine Knight Armor,49.99,Protective gear for brave dog knights!,true
5,Doggy Detective Hat,14.99,For pups with a keen sense of mystery!,true
6,Pup's Princess Tiara,12.99,For the royal doggo in your life!,true
7,Space Dog Helmet,29.99,For pups dreaming of the stars!,true
8,Dog Dino Tail,24.99,Turn your pup into a cute little dino!,true
9,Puppy Elf Ears,7.99,Perfect for the festive season!,true
10,Dog's Cowboy Hat,16.99,For the wild west pup!,true
11,Canine Chef Hat,8.99,For pups who love to cook!,true
12,Doggy Diver Goggles,17.99,For the underwater adventurer!,true
13,Pup's Pilot Cap,18.99,For high-flying dogs!,true
14,Dog's Dragon Wings,27.99,Turn your pup into a mythical creature!,true
15,Puppy Pumpkin Hat,10.99,Perfect for Halloween!,true
16,Dog's Disco Wig,11.99,For the party-loving pup!,true
17,Canine Clown Wig,9.99,For pups who love to entertain!,true
18,Dog's Superhero Mask,6.99,For your little hero!,true
19,Pup's Viking Helmet,21.99,For the brave and bold dog!,true
20,Doggy Ballerina Tutu,15.99,For the graceful dancer!,true
21,Canine Camper Hat,13.99,For the nature-loving pup!,true
22,Dog's Racing Jacket,31.99,For the speedy doggo!,true
23,Puppy's Police Cap,14.99,For the law-abiding pup!,true
24,Dog's Rockstar Jacket,34.99,For the pup with a rock-n-roll soul!,true
25,Canine Captain's Hat,19.99,For the pup who's in charge!,true
mkdir ts-csv-importer
cd ts-csv-importer
npm init -y
npm install typescript @types/node csv-parser fs
npx tsc --init
import * as fs from 'fs';
import * as csv from 'csv-parser';
interface Product {
id: number;
name: string;
price: number;
description: string;
in_stock: boolean;
}
const products: Product[] = [];
fs.createReadStream('products.csv')
.pipe(csv())
.on('data', (row) => {
const product: Product = {
id: Number(row.id),
name: row.name,
price: Number(row.price),
description: row.description,
in_stock: row.in_stock.toLowerCase() === 'true'
};
products.push(product);
})
.on('end', () => {
console.log(products);
// Here, you can transport the 'products' array into a SQL database.
});
bashCopy code
npx tsc importer.ts
node importer.js