File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { PrismaClient } from "@prisma/client" ;
2
+
3
+ const prisma = new PrismaClient ( ) ;
4
+
5
+ const pets = [
6
+ {
7
+ name : "Benjamin" ,
8
+ ownerName : "John Doe" ,
9
+ imageUrl :
10
+ "https://images.unsplash.com/photo-1517849845537-4d257902454a?auto=format&fit=crop&q=100&w=1935&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" ,
11
+ age : 2 ,
12
+ notes :
13
+ "Doesn't like to be touched on the belly. Plays well with other dogs." ,
14
+ } ,
15
+ {
16
+ name : "Richard" ,
17
+ ownerName : "Josephine Dane" ,
18
+ imageUrl :
19
+ "https://images.unsplash.com/photo-1583337130417-3346a1be7dee?auto=format&fit=crop&q=100&w=1964&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" ,
20
+ age : 5 ,
21
+ notes : "Needs medication twice a day." ,
22
+ } ,
23
+ {
24
+ name : "Anna" ,
25
+ ownerName : "Frank Doe" ,
26
+ imageUrl :
27
+ "https://images.unsplash.com/photo-1537151625747-768eb6cf92b2?auto=format&fit=crop&q=100&w=1970&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" ,
28
+ age : 4 ,
29
+ notes : "Allergic to chicken." ,
30
+ } ,
31
+ ] ;
32
+
33
+ async function main ( ) {
34
+ console . log ( `Start seeding ...` ) ;
35
+
36
+ for ( const pet of pets ) {
37
+ const result = await prisma . pet . create ( {
38
+ data : pet ,
39
+ } ) ;
40
+ console . log ( `Created pet with id: ${ result . id } ` ) ;
41
+ }
42
+
43
+ console . log ( `Seeding finished.` ) ;
44
+ }
45
+
46
+ main ( )
47
+ . then ( async ( ) => {
48
+ await prisma . $disconnect ( ) ;
49
+ } )
50
+ . catch ( async ( e ) => {
51
+ console . error ( e ) ;
52
+ await prisma . $disconnect ( ) ;
53
+ process . exit ( 1 ) ;
54
+ } ) ;
You can’t perform that action at this time.
0 commit comments