Skip to content

Instantly share code, notes, and snippets.

@joaoGabriel55
Last active June 8, 2023 18:45
Show Gist options
  • Select an option

  • Save joaoGabriel55/4c7ee7621171029182ff426db4afecd5 to your computer and use it in GitHub Desktop.

Select an option

Save joaoGabriel55/4c7ee7621171029182ff426db4afecd5 to your computer and use it in GitHub Desktop.
Sava data using Dynamoose
const create = async () => {
const user1 = await User.create({
fullName: "John Doe",
email: "john@gmail.com",
birthDate: new Date("2000-01-01"),
addresses: [
{
street: "123 Fake Street",
postalCode: "12345",
state: "CA",
},
],
});
const user2 = await User.create({
fullName: "Eleven Doe",
email: "eleven@gmail.com",
birthDate: new Date("1998-01-01"),
addresses: [
{
street: "123 Example Street",
postalCode: "9999",
state: "SF",
},
],
});
const order1 = await Order.create({
status: "PENDING",
SK: `USER#${user1.id}`,
});
const order2 = await Order.create({
status: "COMPLETED",
SK: `USER#${user2.id}`,
});
await OrderItem.create({
SK: `ORDER#${order1.id}`,
productName: "Product 1",
price: 20,
quantity: 1,
});
await OrderItem.create({
SK: `ORDER#${order1.id}`,
productName: "Product 2",
price: 15,
quantity: 3,
});
await OrderItem.create({
SK: `ORDER#${order2.id}`,
productName: "Product 3",
price: 40,
quantity: 4,
});
};
const run = async () => {
try {
console.log("Table Created");
await create();
} catch (err) {
console.log("Error", err);
}
};
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment