Skip to content

Instantly share code, notes, and snippets.

@millsp
Created April 14, 2021 08:45
Show Gist options
  • Select an option

  • Save millsp/90929394c1da30b33f8378884d9de3b0 to your computer and use it in GitHub Desktop.

Select an option

Save millsp/90929394c1da30b33f8378884d9de3b0 to your computer and use it in GitHub Desktop.

Revisions

  1. millsp created this gist Apr 14, 2021.
    22 changes: 22 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import { PrismaClient, Prisma } from '@prisma/client'

    async function main() {
    const prisma = new PrismaClient()

    // Define a type that includes the relation to `Post`
    const userWithPosts = Prisma.validator<Prisma.UserArgs>()({
    include: { posts: true }
    })

    // Define a type that only contains a subset of the scalar fields
    const userPersonalData = Prisma.validator<Prisma.UserArgs>()({
    select: { email: true, name: true }
    })

    const users = await prisma.user.findMany(userWithPosts)

    console.log(users)
    prisma.$disconnect()
    }

    main()