-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
104 lines (99 loc) · 2.73 KB
/
script.ts
File metadata and controls
104 lines (99 loc) · 2.73 KB
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
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// const prisma = new PrismaClient({log:["query"]})
//we can log query
//allows you to interact with your code with prisma library, so you don't have to write raw sql
async function main() {
// await prisma.user.deleteMany()
// const user = await prisma.user.create({
// data: {
// name: "Kyle",
// email: "kyhle@test.com",
// age:25,
// userPreference:{
// create:{
// emailUpdates:true
// }
// }
// },
// select :{
// name:true,
// userPreference:{
// select:{
// id:true
// }
// }
// }
// // include:{
// // userPreference: true
// // }
// //you can only do select || incude, can't do both at the same time
// })
// const users = await prisma.user.createMany({
// data: [
// {
// name: "Sally",
// email: "sal7lly222@test.com",
// age: 3733,
// }],
// include:{
// userPreference: true
// }
//you can only do select || incude, can't do both at the same time
// })
//finUnique to find properties with unique attributes
// const user1 = await prisma.user.findMany({
// where:{
// OR:[
// { email:{
// startsWith:"Sally"
// }},{
// email:{
// endsWith:"@test.com"
// }
// }
// ],
// age:{
// lt:100
// //less than
// },
// email:{
// // contains:"@test1"
// endsWith: "@test.com"
// }
// // name: { not : "Sally"}
// // email:"sally@test.com",
// } ,
// orderBy:{
// age:"desc"
// }
// // take:1
// })
// const preferences = await prisma.userPreferences.create({
// data:{
// emailUpdates: true
// }
// })
//update will update the first user it finds, and updateMany will update all users
const user1 = await prisma.user.update({
where:{
email:"kyhle@test.com"
},
data:{
userPreference:{
connect:{
id:"4dec53da-1501-4908-a242-36b8d64d0891"
}
}
}
})
console.log(user1)
// ...write prisma client queries here
}
main()
// .catch(e =>{
// console.log(e.message)
// })
// .finally(async()=>{
// await prisma.$disconnect()
// })