forked from prisma/prisma-client-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ts
50 lines (44 loc) · 1.03 KB
/
script.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
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient().$extends({
result: {
user: {
save: {
needs: { id: true, email: true },
compute({ id, email }) {
return () => prisma.user.update({ where: { id }, data: { email } });
},
},
delete: {
needs: { id: true },
compute({ id }) {
return () => prisma.user.delete({ where: { id } });
},
},
},
},
});
async function main() {
const user = await prisma.user.create({
data: { email: "[email protected]" },
});
user.email = "[email protected]";
await user.save();
console.info(
"Updated object: ",
await prisma.user.findUnique({ where: { id: user.id } })
);
await user.delete();
console.info(
"Deleted object: ",
await prisma.user.findUnique({ where: { id: user.id } })
);
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});