easy access to prisma client
This package is for ease of access only so you must install prisma.
yarn add prisma fastify-prisma-client
or
npm install prisma fastify-prisma-client
yarn prisma generate
or
npx prisma generate
Register plugin
import fastifyPrismaClient from "fastify-prisma-client";
fastify.register(fastifyPrismaClient);
If you use with TypeScript , you have to give this type to avoid error
import Fastify, { FastifyInstance } from "fastify";
const fastify: FastifyInstance = Fastify();
Prisma client options are available and you can edit them
fastify.register(fastifyPrismaClient, {});
Use with fastify decorate
fastify.get("/users", async (request, reply) => {
const users = await fastify.prisma.users.findMany();
return { users };
});
Use with request decorate
fastify.get("/users", async (request, reply) => {
const users = await request.prisma.users.findMany();
return { users };
});
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.