Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/balcieren/fastify-prisma-client

Easy access to prisma client
https://github.com/balcieren/fastify-prisma-client

database fastify fastify-plugin orm prisma prisma-client prisma2 typescript

Last synced: 14 days ago
JSON representation

Easy access to prisma client

Awesome Lists containing this project

README

        

# fastify-prisma-client

[![Version](https://img.shields.io/npm/v/fastify-prisma-client.svg)](https://www.npmjs.com/package/fastify-prisma-client)

easy access to prisma client

## Warning !

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

## Installation

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

## Do not forget prisma generate ❗

```bash
yarn prisma generate
or
npx prisma generate
```

## Usage

Register plugin

```js
import fastifyPrismaClient from "fastify-prisma-client";

fastify.register(fastifyPrismaClient);
```

If you use with TypeScript , you have to give this type to avoid error

```js
import Fastify, { FastifyInstance } from "fastify";

const fastify: FastifyInstance = Fastify();
```

Prisma client options are available and you can edit them

```js
fastify.register(fastifyPrismaClient, {});
```

Use with fastify decorate

```js
fastify.get("/users", async (request, reply) => {
const users = await fastify.prisma.users.findMany();
return { users };
});
```

Use with request decorate

```js
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](https://choosealicense.com/licenses/mit/)