From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Seed sample data

Seed sample data

OK, so right now we're getting our products directly from this dbsampledata.ts file, which obviously we don't want to do. We want to get them from our database. Now, we don't have any functionality to add products yet. So to get stuff in our database, we're just going to create a simple seeder, which is just a script that will add products to the database. And what we're going to add is everything that's in this sample data file. So we're going to use this again to populate our database. And then instead of fetching these products directly from the file, we'll then fetch them from the database. And then we can move on to add our functionality to create products and update, edit, and all that, purchase products, and so on. So let's create this in the DB folder. We're going to create a new file called seed.ts. And then we're going to import from here the Prisma client so we can interact with our database. So that's going to be from at slash Prisma. what is it, at Prisma, sorry, Prisma…

Contents