-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
40 lines (32 loc) · 1015 Bytes
/
main.ts
File metadata and controls
40 lines (32 loc) · 1015 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
36
37
38
39
40
import { createClient } from './db';
async function main() {
const db = await createClient();
const user = await db.user.create({ data: { email: 'u1@test.com' }});
console.log('Create a Post');
console.log(
await db.post.create({
data: { name: 'Post1', content: 'First post', ownerId: user.id }
})
);
console.log('Create a Video');
console.log(
await db.video.create({
data: { name: 'Video1', url: 'http://my/video/1', ownerId: user.id }
})
);
console.log('Fetch User with contents');
console.log(
await db.user.findFirstOrThrow({ include: { contents: true } })
);
console.log('Fetch with base Content model, result includes sub model fields');
const content = await db.content.findFirstOrThrow();
console.log(content);
console.log('Delete Videos');
await db.video.deleteMany();
console.log('Remaining Content entities:');
// deletion of concrete entities cascades to the base
console.log(
await db.content.findMany()
);
}
main();