从零搭建基于 AI 问答平台(7) 定义Quiz 数据模型

添加模型定义

修改 prisma/schema.prisma:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
enum GameType {
mcq
open_ended
}

model Game {
id String @id @default(cuid())
userId String
questions Question[]
timeStarted DateTime
topic String
timeEnded DateTime?
gameType GameType

@@index([userId])
}

model topic_count {
id String @id @default(cuid())
topic String @unique
count Int
}

model Question {
id String @id @default(cuid())
question String
answer String
gameId String
options Json? // for mcq questions
percentageCorrect Float? // for open_ended questions
isCorrect Boolean? // for mcq questions
questionType GameType
userAnswer String?

game Game @relation(fields: [gameId], references: [id])

@@index([gameId])
}

执行:

1
bunx prisma db push

检查已定义的表

1
bunx prisma studio

打开 http://localhost:5555/, 可以看到已定义的表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export const quizCreationSchema = z.object({
topic: z
.string()
.min(4, {
message: "Topic must be at least 4 characters long",
})
.max(50, {
message: "Topic must be at most 50 characters long",
}),
type: z.enum(["mcq", "open_ended"]),
amount: z.number().min(1).max(10),
});

const form = useForm<Input>({
resolver: zodResolver(quizCreationSchema),
defaultValues: {
topic: topicParam,
type: "mcq",
amount: 3,
},
});

作者:Bearalise
出处:从零搭建基于 AI 问答平台(7) 定义Quiz 数据模型
版权:本文版权归作者所有
转载:欢迎转载,但未经作者同意,必须保留此段声明,必须在文章中给出原文链接。

请我喝杯咖啡吧~

支付宝
微信