From 2b409c68497f5bd39eae42d6ee5f1d39743dc598 Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Fri, 3 Feb 2023 10:19:48 -0800 Subject: [PATCH] Add prisma setup for example. --- examples/blog-engine/prisma/schema.prisma | 18 ++++++++++++++++++ examples/blog-engine/prisma/seed.mjs | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 examples/blog-engine/prisma/schema.prisma create mode 100644 examples/blog-engine/prisma/seed.mjs diff --git a/examples/blog-engine/prisma/schema.prisma b/examples/blog-engine/prisma/schema.prisma new file mode 100644 index 00000000..1c08267a --- /dev/null +++ b/examples/blog-engine/prisma/schema.prisma @@ -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 +} diff --git a/examples/blog-engine/prisma/seed.mjs b/examples/blog-engine/prisma/seed.mjs new file mode 100644 index 00000000..2de84ed4 --- /dev/null +++ b/examples/blog-engine/prisma/seed.mjs @@ -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, + }); +});