-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgroup-by.ts
More file actions
32 lines (28 loc) · 689 Bytes
/
group-by.ts
File metadata and controls
32 lines (28 loc) · 689 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
import { createClient } from './db';
import { createUsersAndPosts } from './utils';
async function main() {
const db = await createClient();
await createUsersAndPosts(db);
console.log('Post grouped by "published"');
console.log(
await db.post.groupBy({
by: ['published'],
_count: { content: true },
_avg: { viewCount: true }
})
);
console.log('Post grouped by "published" and filtered for average viewCount');
console.log(
await db.post.groupBy({
by: ['published'],
_count: { content: true },
_avg: { viewCount: true },
having: {
viewCount: {
_avg: { gt: 1 }
}
}
})
);
}
main();