-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js
50 lines (46 loc) · 884 Bytes
/
seed.js
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
44
45
46
47
48
49
50
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
const userData = [
{
name: 'Jane',
email: '[email protected]',
posts: {
create: [
{
title: 'First Post',
content: 'Hello, World!',
},
],
},
},
{
name: 'Joe',
email: '[email protected]',
posts: {
create: [
{
title: 'Second Post',
content: 'Hello, Journal!',
},
],
},
},
];
async function main() {
console.log(`Start seeding ...`);
for (const u of userData) {
const user = await prisma.user.create({
data: u,
});
console.log(`Created user with id: ${user.id}`);
}
console.log(`Seeding finished.`);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});