-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathscript.ts
42 lines (38 loc) · 1010 Bytes
/
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
import { PrismaClient } from "@prisma/client";
import { performance } from "perf_hooks";
import * as util from "util";
const prisma = new PrismaClient().$extends({
query: {
$allModels: {
async $allOperations({ operation, model, args, query }) {
const start = performance.now();
const result = await query(args);
const end = performance.now();
const time = end - start;
console.log(
util.inspect(
{ model, operation, args, time },
{ showHidden: false, depth: null, colors: true }
)
);
return result;
},
},
},
});
async function main() {
await prisma.user.findMany({
orderBy: [{ lastName: "asc" }, { firstName: "asc" }],
take: 5,
});
await prisma.user.groupBy({ by: ["lastName"], _count: true });
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});