-
Notifications
You must be signed in to change notification settings - Fork 15
/
script.ts
46 lines (39 loc) · 1.09 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
import { PrismaClient } from "@prisma/client";
const adminPrisma = new PrismaClient();
const publicPrisma = adminPrisma.$extends({
query: {
post: {
$allOperations({ args, query, operation }) {
// Do nothing for `create`
if (operation === "create") {
return query(args);
}
// Refine the type - methods other than `create` accept a `where` clause
args = args as Extract<typeof args, { where: unknown }>;
// Augment the `where` clause with `published: true`
return query({
...args,
where: {
...args.where,
published: true,
},
});
},
},
},
});
async function main() {
const allPosts = await adminPrisma.post.count();
console.log(`- All posts: ${allPosts}`);
const publishedPosts = await publicPrisma.post.count();
console.log(`- Published posts: ${publishedPosts}`);
}
main()
.then(async () => {
await adminPrisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await adminPrisma.$disconnect();
process.exit(1);
});