-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
43 lines (39 loc) · 909 Bytes
/
script.ts
File metadata and controls
43 lines (39 loc) · 909 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
41
42
43
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// A `main` function so that you can use async/await
async function main() {
const user2Exist = await prisma.user.count({
where: { id: 2 }
});
if (user2Exist === 0) {
await prisma.user.create({
data: {
email: 'ariadne@prisma.io',
name: 'Ariadne',
posts: {
create: [
{
title: 'My first day at Prisma',
},
{
title: 'How to connect to a SQLite database',
},
],
},
},
})
}
const allUsers = await prisma.user.findMany({
where: { id: 1 },
include: { posts: true },
})
// use `console.dir` to print nested objects
console.dir(allUsers, { depth: null })
}
main()
.catch(e => {
throw e
})
.finally(async () => {
await prisma.$disconnect()
})