Update blog db seed file.

This commit is contained in:
Dillon Kearns 2023-02-05 17:08:38 -08:00
parent 202a8bf666
commit 087a73e97f
3 changed files with 24 additions and 22 deletions

View File

@ -1,5 +1,6 @@
{
"name": "elm-pages-example",
"type": "module",
"version": "1.0.0",
"description": "Example site built with elm-pages.",
"scripts": {
@ -27,5 +28,8 @@
"dependencies": {
"@prisma/client": "^4.9.0",
"bcryptjs": "^2.4.3"
},
"prisma": {
"seed": "node prisma/seed.js"
}
}

View File

@ -0,0 +1,20 @@
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
[...Array(9).keys()].forEach(async (index) => {
let slug = `${index + 1}`;
const post = { title: slug, body: slug, slug };
await prisma.post.upsert({
where: { slug },
update: post,
create: post,
});
});
// posts.forEach(async (post) => {
// await prisma.post.upsert({
// where: { slug: post.slug },
// update: post,
// create: post,
// });
// });

View File

@ -1,22 +0,0 @@
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const posts = [
{
slug: "elm-pages demo",
title: "Is elm-pages Full-Stack?",
body: `
# Is elm-pages Full-Stack?
Yes it is!
`.trim(),
},
];
posts.forEach(async (post) => {
await prisma.post.upsert({
where: { slug: post.slug },
update: post,
create: post,
});
});