0.3.1 • Published 5 months ago

prisma-extension-selecting v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

prisma-extension-selecting

A Prisma client extension for setting select and include permanently for a model.

Installation

npm install prisma-extension-selecting

Usage

import { PrismaClient } from '@prisma/client'
import selecting from 'prisma-extension-selecting'

// apply the extension
const prisma = new PrismaClient().$extends(selecting)

// set "select" and/or "include" once and those values
// will be used for all applicable queries on `users`
const users = prisma.user.selecting({
  select: {
    id: true,
    name: true,
    posts: { select: { title: true } },
  },
})

// type UserWithPosts = { name: string; id: number; posts: { title: string; }[] }
type UserWithPosts = Prisma.UserGetPayload<typeof users.selection>

// all these queries will return only the fields selected above
users.create({ data: { ... } });
users.findMany();
users.findFirst({ where: { ... } });
users.findUniqueOrThrow({ where: { ... } });
users.update({ where: { ... }, data: { ... } });
users.delete({ where: { ... } });
0.3.1

5 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago

0.0.2

9 months ago

0.0.1

9 months ago