-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
231 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_ENV = "development" | ||
|
||
HANA_DATABASE_URL = "postgresql://your_username:your_password@localhost:5432/grey_flowers?schema=public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import process from 'node:process' | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
function prismaClientSingleton() { | ||
return new PrismaClient() | ||
} | ||
|
||
declare const globalThis: { | ||
prismaGlobal: ReturnType<typeof prismaClientSingleton> | ||
// eslint-disable-next-line no-restricted-globals | ||
} & typeof global | ||
|
||
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton() | ||
|
||
export default prisma | ||
|
||
if (process.env.NODE_ENV !== 'production') | ||
globalThis.prismaGlobal = prisma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("HANA_DATABASE_URL") | ||
} | ||
|
||
model Article { | ||
id Int @id @default(autoincrement()) | ||
title String @unique | ||
description String? | ||
cover String? | ||
alt String @unique | ||
ogImage String? | ||
publishedAt DateTime @default(now()) | ||
editedAt DateTime @updatedAt | ||
published Boolean @default(false) | ||
wordCount Int @default(0) | ||
tags Tag[] @relation("ArticleTags") | ||
category Category? @relation(fields: [categoryId], references: [id]) | ||
categoryId Int? | ||
comments Comment[] // 文章的评论 | ||
} | ||
|
||
model Tag { | ||
id Int @id @default(autoincrement()) | ||
name String @unique | ||
articleCount Int @default(0) | ||
articles Article[] @relation("ArticleTags") | ||
} | ||
|
||
model Category { | ||
id Int @id @default(autoincrement()) | ||
name String @unique | ||
cover String? | ||
articleCount Int @default(0) | ||
articles Article[] | ||
} | ||
|
||
model User { | ||
id Int @id @default(autoincrement()) | ||
email String @unique | ||
name String? @default("佚名") | ||
site String? | ||
avatar String? | ||
comments Comment[] | ||
replies Comment[] @relation("ReplyToUser") | ||
messages Message[] | ||
} | ||
|
||
model Comment { | ||
id Int @id @default(autoincrement()) | ||
content String | ||
level CommentLevel @default(PARENT) | ||
parentId Int? | ||
parent Comment? @relation("ParentChild", fields: [parentId], references: [id]) | ||
children Comment[] @relation("ParentChild") | ||
article Article? @relation(fields: [articleId], references: [id]) | ||
articleId Int? | ||
author User? @relation(fields: [authorId], references: [id]) | ||
authorId Int? | ||
replyToUser User? @relation("ReplyToUser", fields: [replyToUserId], references: [id]) | ||
replyToUserId Int? | ||
publishedAt DateTime @default(now()) | ||
editedAt DateTime @updatedAt | ||
} | ||
|
||
model Message { | ||
id Int @id @default(autoincrement()) | ||
content String | ||
parentId Int? | ||
parent Message? @relation("ParentChild", fields: [parentId], references: [id]) | ||
children Message[] @relation("ParentChild") | ||
author User? @relation(fields: [authorId], references: [id]) | ||
authorId Int? | ||
publishedAt DateTime @default(now()) | ||
editedAt DateTime @updatedAt | ||
} | ||
|
||
enum CommentLevel { | ||
PARENT | ||
CHILD | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default defineEventHandler((event) => { | ||
return { | ||
hello: 'world', | ||
eventInfo: event, | ||
} | ||
}) |