Add prisma setup for example.

This commit is contained in:
Dillon Kearns 2023-02-03 10:19:48 -08:00
parent f08b0c3564
commit 2b409c6849
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,18 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}
datasource db {
provider = "postgresql"
url = env("BLOG_DATABASE_URL")
}
model Post {
title String
slug String @id
body String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

View File

@ -0,0 +1,22 @@
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,
});
});