Prisma
Provider backed by Prisma
Prisma
Better Blog can be used with Prisma and a PostgreSQL database.
Environment Variables
POSTGRES_URL=
Installation
pnpm add -D prisma
pnpm add @prisma/client
Update your schema to match the one below, and generate the client:
pnpm prisma generate
Schema
// schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}
model Post {
id String @id @default(dbgenerated("gen_random_uuid()"))
authorId String?
defaultLocale String @default("en")
title String
slug String @unique
excerpt String @db.Text
content String @db.Text
image String?
version Int @default(1)
status String @default("DRAFT")
i18n PostI18n[]
tags PostTag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@index([status, updatedAt])
}
model PostI18n {
id String @id @default(dbgenerated("gen_random_uuid()"))
postId String
locale String
title String
slug String
excerpt String @db.Text
content String @db.Text
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
@@unique([postId, locale])
@@unique([locale, slug])
@@index([locale])
}
model Tag {
id String @id @default(dbgenerated("gen_random_uuid()"))
defaultLocale String @default("en")
name String
slug String @unique
i18n TagI18n[]
posts PostTag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model TagI18n {
id String @id @default(dbgenerated("gen_random_uuid()"))
tagId String
locale String
name String
slug String
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@unique([tagId, locale])
@@unique([locale, slug])
@@index([locale])
}
model PostTag {
postId String
tagId String
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([postId, tagId])
@@index([tagId])
}
Example usage
// lib/blog-data-provider.ts
import { createPrismaProvider } from "better-blog/server/prisma"
import prisma from "./prisma";
export function createBlogDataProvider() {
return createPrismaProvider({
prisma: prisma
})
}