Skip to content

Instantly share code, notes, and snippets.

@HectorBlisS
Last active November 3, 2022 03:10
Show Gist options
  • Save HectorBlisS/0baf497cd886cd524391584f8206d132 to your computer and use it in GitHub Desktop.
Save HectorBlisS/0baf497cd886cd524391584f8206d132 to your computer and use it in GitHub Desktop.
const faker = require('@faker-js/faker').faker // commonjs
const PrismaClient = require('@prisma/client').PrismaClient
const prisma = new PrismaClient()
const getProduct = ()=> {
const name = faker.commerce.productName()
return ({
slug:faker.helpers.slugify(name),
name,
body:faker.commerce.productDescription(),
images:[
faker.image.imageUrl(),
faker.image.imageUrl(),
faker.image.imageUrl(),
],
color: faker.color.human()
})
}
const saveInDB = async () => prisma.product.create({data:getProduct()}) // <== Cambia este create por .createMany y coloca la lógica necesaria
const seed = async()=>{
await Promise.all([...Array(20).keys()].map(saveInDB))
}
seed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment