Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

balcieren/fastify-prisma-client

Repository files navigation

fastify-prisma-client

Version

easy access to prisma client

Warning !

This package is for ease of access only so you must install prisma.

Installation

yarn add prisma fastify-prisma-client
or
npm install prisma fastify-prisma-client

Do not forget prisma generate ❗

yarn prisma generate
or
npx prisma generate

Usage

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 };
});

Contributing

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.

License

MIT