|
| 1 | +const { PrismaClient } = require("@prisma/client"); |
| 2 | +const prisma = new PrismaClient(); |
| 3 | + |
| 4 | +exports.handler = async (event, context, callback) => { |
| 5 | + try { |
| 6 | + await Promise.all([prisma.profile.deleteMany(), prisma.post.deleteMany()]); |
| 7 | + await prisma.user.deleteMany(); |
| 8 | + |
| 9 | + const createdUser = await prisma.user.create({ |
| 10 | + data: seedUser, |
| 11 | + }); |
| 12 | + |
| 13 | + const createdUser2 = await prisma.user.create({ |
| 14 | + data: seedUser2, |
| 15 | + }); |
| 16 | + |
| 17 | + return { |
| 18 | + statusCode: 201, |
| 19 | + headers: { "Content-Type": "application/json" }, |
| 20 | + body: JSON.stringify([createdUser, createdUser2]), |
| 21 | + }; |
| 22 | + } catch (error) { |
| 23 | + console.error(error); |
| 24 | + return { statusCode: 500 }; |
| 25 | + } |
| 26 | +}; |
| 27 | + |
| 28 | +const seedUser = { |
| 29 | + |
| 30 | + name: "Jane", |
| 31 | + profile: { |
| 32 | + create: { |
| 33 | + bio: "Health Enthusiast", |
| 34 | + }, |
| 35 | + }, |
| 36 | + posts: { |
| 37 | + create: [ |
| 38 | + { |
| 39 | + title: |
| 40 | + "Comparing Database Types: How Database Types Evolved to Meet Different Needs", |
| 41 | + content: |
| 42 | + "https://www.prisma.io/blog/comparison-of-database-models-1iz9u29nwn37/", |
| 43 | + }, |
| 44 | + { |
| 45 | + title: "Analysing Sleep Patterns: The Quantified Self", |
| 46 | + content: "https://quantifiedself.com/get-started/", |
| 47 | + }, |
| 48 | + { |
| 49 | + title: "Prisma 2 Docs", |
| 50 | + content: "https://www.prisma.io/docs/", |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | +}; |
| 55 | + |
| 56 | +const seedUser2 = { |
| 57 | + |
| 58 | + name: "Toru Takemitsu", |
| 59 | + profile: { |
| 60 | + create: { |
| 61 | + bio: "Musician", |
| 62 | + }, |
| 63 | + }, |
| 64 | + posts: { |
| 65 | + create: [ |
| 66 | + { |
| 67 | + title: "Requiem for String Orchestra", |
| 68 | + content: "", |
| 69 | + }, |
| 70 | + { |
| 71 | + title: "Music of Tree", |
| 72 | + content: "", |
| 73 | + }, |
| 74 | + { |
| 75 | + title: "Waves for clarinet, horn, two trombones and bass drum ", |
| 76 | + content: "", |
| 77 | + }, |
| 78 | + ], |
| 79 | + }, |
| 80 | +}; |
0 commit comments