Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/balcieren/fastify-prisma-client
- Owner: balcieren
- License: mit
- Created: 2021-06-30T09:18:22.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T03:34:28.000Z (6 months ago)
- Last Synced: 2024-05-22T04:32:43.809Z (6 months ago)
- Topics: database, fastify, fastify-plugin, orm, prisma, prisma-client, prisma2, typescript
- Language: TypeScript
- Homepage:
- Size: 2.95 MB
- Stars: 12
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
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/)