| 9 | const prisma = new PrismaClient({ adapter }) |
| 10 | |
| 11 | async function main() { |
| 12 | // create user |
| 13 | const user = await prisma.user.create({ |
| 14 | data: { |
| 15 | email: 'hana@hana.io', |
| 16 | name: 'Hana', |
| 17 | }, |
| 18 | }) |
| 19 | |
| 20 | console.log(user) |
| 21 | |
| 22 | // find user |
| 23 | const foundUser = await prisma.user.findUnique({ |
| 24 | where: { |
| 25 | email: 'hana@hana.io' |
| 26 | } |
| 27 | }) |
| 28 | console.log(foundUser) |
| 29 | |
| 30 | // update user |
| 31 | const updatedUser = await prisma.user.update({ |
| 32 | where: { |
| 33 | email: 'hana@hana.io', |
| 34 | }, |
| 35 | data: { |
| 36 | name: 'Peters', |
| 37 | }, |
| 38 | }) |
| 39 | console.log(updatedUser) |
| 40 | |
| 41 | // delete user |
| 42 | const deleteUser = await prisma.user.delete({ |
| 43 | where: { |
| 44 | email: 'hana@hana.io', |
| 45 | } |
| 46 | }) |
| 47 | console.log("User deleted", deleteUser) |
| 48 | |
| 49 | // create user with posts |
| 50 | const userPosts = await prisma.user.create({ |
| 51 | data: { |
| 52 | email: 'dave@prisma.io', |
| 53 | name: 'David', |
| 54 | posts: { |
| 55 | create: [ |
| 56 | { title: 'Hello world' }, |
| 57 | { title: 'Introduction to Prisma with Mongo' }, |
| 58 | { title: 'MongoDB and schemas' }, |
| 59 | ], |
| 60 | }, |
| 61 | }, |
| 62 | include: { |
| 63 | posts: true, |
| 64 | }, |
| 65 | }) |
| 66 | |
| 67 | console.dir(userPosts, { depth: Infinity }) |
| 68 | |