-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprisma_test.ts
51 lines (44 loc) · 943 Bytes
/
prisma_test.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const id = await create();
console.log("생성");
await read(id);
await update(id);
console.log("수정");
await read(id);
await destroy(id);
console.log("삭제");
await read(id);
}
async function create() {
const { id } = await prisma.question.create({
data: {
subject: "제목",
content: "내용",
},
});
return id;
}
async function read(id: string) {
try {
const question = await prisma.question.findUnique({
where: { id },
});
console.log("read: ", question);
} catch (error) {
console.log(`id: ${id} not found`);
}
}
async function update(id: string) {
await prisma.question.update({
where: { id },
data: { subject: "제목2" },
});
}
async function destroy(id: string) {
await prisma.question.delete({
where: { id },
});
}
main();