-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
35 lines (28 loc) · 795 Bytes
/
main.ts
File metadata and controls
35 lines (28 loc) · 795 Bytes
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
import { createClient } from './db';
import { createUsersAndPosts } from './utils';
async function main() {
const db = await createClient();
await createUsersAndPosts(db);
console.log('Computed fields are returned with query results');
console.log(
await db.user.findFirst()
);
console.log('You can select them explicitly too');
console.log(
await db.user.findFirst({ select: { email: true, postCount: true }})
);
console.log('You can also use them for filtering and sorting');
console.log(
await db.user.findFirst({
where: { postCount: { gt: 1 } },
orderBy: { postCount: 'desc' }
})
);
console.log('You can also aggregate over them');
console.log(
await db.user.aggregate({
_avg: { postCount: true }
})
);
}
main();