-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
107 lines (94 loc) · 2.41 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
// Create user
// const user = await prisma.user.create({
// data:{
// name:"Richa",
// email:"[email protected]"
// },
// })
// get all users
// const users = await prisma.user.findMany();
// console.log(users);
// create an article
// const article = await prisma.article.create({
// data: {
// title:"Nanhu book",
// body:"Nanhu is cute and sweet",
// author:{
// connect:{
// id:1
// }
// },
// },
// });
// Get all articles
// const articles = await prisma.article.findMany();
// console.log(articles)
// Create user and article and associate them.
// const user = await prisma.user.create({
// data:{
// name:"Richa",
// email: "[email protected]",
// articles:{
// create:{
// title:"Piyu Book",
// body:"Pyari piyu book has ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// }
// }
// }
// })
// show users with their articles
// const userWithArticles = await prisma.user.findMany({
// include:{
// articles: true
// }
// })
// create another article
// const article = await prisma.article.create({
// data:{
// title:"Cute Nanhu",
// body:"Nanhu is cute and sweet. Smallest member of our family.",
// author:{
// connect:{
// id:2
// }
// }
// }
// })
// console.log(userWithArticles);
// userWithArticles.forEach(user=>{
// console.log(`User: ${user.name} Email: ${user.email}`);
// console.log("Articles:--");
// user.articles.forEach(article=>{
// console.log(`- Title: ${article.title} Body: ${article.body}`);
// })
// console.log("\n")
// })
// Update users
// const user = await prisma.user.update({
// where: {
// id:1,
// },
// data:{
// name:"Piyu"
// }
// })
// console.log(user)
// Remove Data
// const article = await prisma.article.delete({
// where:{
// id: 2
// }
// });
// console.log(article)
}
main()
.then(async () => {
await prisma.$disconnect();
}).catch(async (e)=>{
console.error(e);
await prisma.$disconnect();
process.exit(1);
})