Seeder

seed.ts

import { PrismaClient } from '../src/generated/prisma';

const prisma = new PrismaClient();

async function main() {
    await prisma.product.deleteMany({});

    const products = [
        {
          name: "Basreng",
          price: 500,
          stock: 20
        },
        {
          name: "Cilok", 
          price: 1000,
          stock: 40
        },
        {
          name: "Sate",
          price: 2000,
          stock: 50
        }
      ];

    for (const product of products) {
        await prisma.product.create({
          data: product
        });
    }
    
      console.log('Seeding completed!');
}

main()
    .catch((e) => {
        console.error(e);
        process.exit(1);
    })
    .finally(async () => {
        await prisma.$disconnect();
    });

Last updated